XML: contents.replace () destroyed XML elements inside

Hello

I wrote a script XML rule where all the < ul > < li > is mapped to a paragraph style that uses bulleted lists. It is possible that returns occur inside the < li > elements. Before you go through the items and by applying styles with a script rule, I tried to change the return (\r) of returns (\n) cycling through all the < li > with this code:

_node.contents = _node.contents.replace(/\r/g, '\n');  //change all returns inside <usp><li> to newline

But I realized that, when there are other XML elements (for example < em > or < strong >) inside the < li >, these elements have been killed by my call of. replace().

So my question: How can I reach evolution \r's to \n's and keep inside XML structure?

Thanks in advance

Tobias

I did it with this chiseled script - function grep with emphasis on the XML element - executed after that all XML was processed and placed in the document:

  // change \r to \n in usp's li's
  app.findGrepPreferences = NothingEnum.NOTHING; app.changeGrepPreferences = NothingEnum.NOTHING;
  var _root = _dok.xmlElements[0];
  var _nodeList = _root.evaluateXPathExpression("//li");
  app.findGrepPreferences.findWhat = "\\r"; app.changeGrepPreferences.changeTo = "\\n";
    for ( i = 0; i < _nodeList.length; i++ ) {
        var _node = _nodeList[i];
        if ( _node.contents != "" ) {
            _node.changeGrep();
        }
    }
  app.findGrepPreferences = NothingEnum.NOTHING; app.changeGrepPreferences = NothingEnum.NOTHING;

It works perfectly. Any other suggestions?

Thank you

Tobias

Tags: InDesign

Similar Questions

  • CDATA XML element inside mxml

    Hello

    I get confused about how the syntax to create a CDATA element in the script block in the mxml file. I do and I get a parse error:

    var tmpStr:XML = new XML ("<!") ("[CDATA [" + notes.text + "']] >");
    xmlFile.notes.tag = tmpStr;
    Results.Text = xmlFile.toXMLString ();

    I tried to use a backslash to escape to the "<" and ">" but which resulted in inconsistent behavior with the second line when I reread the xml file as on a mac, it reproduces the CDATA block and on the sides of linux and Windows he removed CDATA tags. Any help would be appreciated.

    Thank you
    Hoyt

    Breaking the closing of the CDATA node tag:
    var tmpStr:XML = new XML(" ");
    Tracy

  • How to add content in the xml element?

    I need to insert a word sqrt (plain text without tags) in the xml element of m:msqrt as below:

    enter image description here

    I tried,

         

    var path = (app.activeDocument.fullName.parent.fsName) m:System.NET.SocketAddress.ToString () replace (/ \ / g, ' /'); document path (sample.indd) active

    var xmlPath = (app.activeDocument.fullName.parent.fsName) m:System.NET.SocketAddress.ToString (.replace(/\\/g, '/')) + "" / with_aid2.xml ";"

    xmlFile = file (xmlPath);

    {if (xmlFile.Exists)}

    xmlFile.open ();

    var myString = xmlFile.read ();

    xmlFile.close ();

    myXml = new XML ();

    myXml = XML (myString);

    var msqrtCount = myXml.xpath("//m:msqrt");

    } else {alert (xmlPath + "does not exist!") ;}}

    for (var i = 0; i < msqrtCount.length (); i ++) {}

    var added = msqrtCount [i];

    added.contents = "sqrt";

    }

    I get an error indicates the invalid content property.

    Try this,

    var myDoc = app.activeDocument;
    mySqrtTag(myDoc)
    function mySqrtTag(elm)
    {
        for (var i = 0; i < elm.xmlElements.length; i++)
        {
            if(elm.xmlElements[i].markupTag.name.toString() == "m:msqrt")
            {
                elm.xmlElements[i].insertionPoints[0].contents = "sqrt";
            }
            mySqrtTag(elm.xmlElements[i]);
        }
    }
    
  • How to pass the content of an xml element in the text frame in inDesign Script

    var XMLFile = File.openDialog ("select XML Files... ») ;

    var doc = app.activeDocument;

    If (!) App.Documents.Length)

    {alert ("ERROR: Document not opened");}

    return;

    }

    doc.importXML (XMLFile);

    var firstFigureNode = doc.xmlElements [0] .xmlElements [1] .xmlElements [0];

    var lableNode = firstFigureNode.xmlElements [0];

    var lableNodeText = lableNode.contents;

    myFrame var = doc.textFrames.add ({geometricBounds: [-13, 13, 3, -3]});

    lableNodeText.move (LocationOptions.AFTER, myFrame.texts [0]);

    ========================================================

    My requirement is: == > > move the content of an xml element in the text by inDesign Script block, but XML InDesign file Structure should not be change & data in the XML Structure should remain as it was before...

    I tried to code above, but it does not work...

    Please can someone help me in solving this problem...

    It does not work correctly...

    It moves firstFigureNode in myFrame...

    firstFigureNode.placeXML (myFrame);

    ===>> For Apple Script try below Code ===>>

    myFrame markup using firstFigureNode

  • I'm new in indesign scripting, please tell me how to write a script to get the contents of an XML element and then sort all the content

    I'm new in indesign scripting, please tell me how to write a script to get the contents of an XML element and then sort all the content

    Hello

    Can the code below is useful for you, but I do not know how to sort.

    Change the tag based on your employment application.

  • How to separate the content of the XML element

    Hi all

    How can we separate content of the XML element in two strings, where each string will be copied to new variables.

    For ex:
    The entry that I get is

    C:/documents/sharedFiles/Apple.PDF < XmLElement > < / XMLElement >

    now I want to break the content into two parts as

    < yyyy > C:/documents/sharedFiles / < / aaaaa >
    Apple.PDF < bath > < / bath > (I want to separate the file name string)

    and now I want to copy it in two other variables. How can I achieve this in BPEL. Appreciate your help.

    Thank you

    Published by: kameshb on March 25, 2013 11:16

    Hi Philippe,.

    I tried this on a simple XSL and achieve the desired results:

    Entry:
    ------------

    C:/test/dummy/post/test.PDF










    It will be useful.

    Thank you
    Deepak.

  • MN jobs XML elements

    Hi all

    I need to get out the marginal following tags in XML jobs.

    I hope that the problem is in line 18 coding.

    Screenshot:

    Screen Shot 2014-07-17 at 11.14.24 AM.png

    The coding is below:

    var myDoc = app.activeDocument;  
    
    var myLib = app.libraries[0];
    
    var myXMLElement = app.activeDocument.xmlElements[0].evaluateXPathExpression("//marginalnote");
    
    alert(myXMLElement.length);
    
    for(i=myXMLElement.length-1; i>0; i--)
    
    {
            var myText = myXMLElement[i].texts[0];
            
            alert(myText.contents)
            
            var myLibraryAsset = app.libraries[0].assets.item("box").placeAsset(myXMLElement[i].insertionPoints[-1])[0];
            
            var myTextMove = myXMLElement[i].texts[0].move(LocationOptions.AT_END, myLibraryAsset.insertionPoints[0])           //Problem in this only
            
             myLibraryAsset.appliedObjectStyle = myDoc.objectStyles.item("Box")
    
            myLibraryAsset.fit(FitOptions.frameToContent)
    
        }
    
    
    
    
    
    
    
    
    

    Thanks in advance

    Siraj

    As I read in your source, without attempting to reproduce the environment:

    When you place your library assets, the result (a places 'box' page element, not a library asset more) is found in the xml element. According to means grounded in the text of content via a special character. That the special character is your problem, because it is found in your text [0]. So the error message means that you can't move that character to anchor in the anchor block.

    To resolve this problem, place the assets in the library outside of the xml element. I had also tag the frame rather than leaving the empty tag in the text. There is a nice method by combining these operations call.

    You can further optimize if you place the 'box' that only once, for example on a unused master page, then use the second parameter of placeIntoInlineCopy() to produce copies. I think it's a bug that after my 'fake' I still remove TF1.

    var x = app.activeDocument.xmlElements.item(0).evaluateXPathExpression("//P") [0];

    var box = app.libraries [0].assets.item ('box');

    TF1 = box.placeAsset (xe.storyOffset) var [0];

    TF2 var = xe.placeIntoInlineCopy (tf1, false);

    TF1. Remove();

  • Loop through all of the xml elements

    How do I loop over all xml tagged in a story? I created a reference to the xml elements of the story I want to like this:

    var xmlStory = myDoc.xmlElements[0].xmlElements[0];
    

    In this structure, I have items < v > 10 / < v >, which I want to change of < id v '10' = > 10 / < v >. I want to do in the InDesign scripting and not with XSL export because of workflow, I plan. I know I can loop on children in the structure like this:

    for(var i=0;i<xmlStory.xmlElements.length;i++){
                        if(xmlStory.xmlElements[i].markupTag.name == "v"){
                                  xmlStory.xmlElements[i].xmlAttributes.add("id", xmlStory.xmlElements[i].contents);
                       }
             }
    

    This works very well for the first level, but I want to find all elements with the tag '< v >. These tags can appear at any level in the structure. How can I make sure that all of them are included and not just the first elements of the child of the element of the story?

    Try this,

    #target inDesign;

    var doc = app.activeDocument;
    xmlTag var = doc.xmlElements [0];
    var vTag = xmlTag.evaluateXPathExpression("//v")
    for (var i = 0; i)<>
    {
    Try
    {
    vTag [i].xmlAttributes.add ("id", vTag [i].xmlContent.contents)
    }
    {catch (e)}
    }

  • that means xml, when I try to set up an analysis of the image years ago, I get the message that there are on this scan xml elements and if I save it, elments of xml will be cleared. What is

    When I bring up some old pictures on my computer, it comes like a scan, when I opened the scan he says he has xml elements, which, if I save it, the xml elements will be deleted, what are xml elements

    The normal definition of xml is the Extensible Markup Language and is the most used in the web development. There is no logical reason why scans contain xml in their breast.

    All files have an extension that is used by Windows to identify what program to use to open the file. Word uses .doc or .docx format, Excel .xls or .xlsx, Adobe uses .pdf etc.

    Right-click on one of the files and select Properties, in the general tab, it displays the type of file and its extension.

    You are referring to 'initials pvt' but pvt isn't a common file extension and is used by a couple of applications, but have nothing to do with analysis or graphics.

    Up to what you did what in fact do a copy files (copy the directory as a whole) and let the originals intact.

    Although Word works with graphics files which is not normally the native program to use, can you explain the steps that you use to open the files.

  • Create the XML element for the cell in the chart CC2015

    Hello world

    I am currently working with the xml element.

    And I want to create xml, table cell element.

    For now, I can create xml for the graphic cell by select graphic image of that cell, and then call the AutoTag() function.

    But I want to create an xml element of a chart without selected cell.

    I found the function () Utils < IXMLElementCommands >-> CreateElement()

    but it doesn't seem to work with a graphic table cell structure.

    Does anyone know how to do?

    Thanks in advance.

    Try,

    InterfacePtr cellContent (tableModel-> QueryCellContentBoss (gridAddress));

    if(cellContent == Nil) {}

    break;

    }

    InterfacePtr cellXMLReferenceData (cellContent, UseDefaultIID());

    {if(!cellXMLReferenceData)}

    break;

    }

    XMLReference cellXMLRef is cellXMLReferenceData-> GetReference();.

  • XML: Management Styles with yields within XML elements

    Hello

    I get XML source, which may contain flashbacks (\r) within an XML element representing the various paragraphs, for example:

    < bodytext > This is the text of the first paragraph.

    And the following paragraph.

    And so on... < / bodytext >

    It is easy to apply a style to the whole paragraph < bodytext > XML scripting rules. But what PARAGRAPH < bodytext > should have a different paragraph style, which applies to a drop cap: How can I do this?

    Thanks in advance

    Tobias

    Why don't reach you the paragraph of xmlElement object and apply the style?

    myXMLElement.paragraphs [0] .appliedParagraphStyle = myParaStyle;

    ?

  • Check for the existing XML element

    Hi all

    I'm writing a simple script first check if an XML element exists and creating so if it's not. I tried to change a piece of code that I used previously to do the same for paragraph styles, but apparently it's not that simple. Currently, all I get is the error "Unable to run the script in the 'main' target engine!" Without checking them, adding the XML element based on the result of the search works very well.

    /* Find all instances of the word "Superscript" */
    app.findTextPreferences.findWhat = "Superscript";
    var mySuperscript = myDocument.findText(); // Save search result for future reference
    
    /* See if an XML element named "Superscript" already exists, and create it if that's not the case; then add it to all instances of the word "Superscript" */
    var myXMLElementSuper = myDocument.xmlElements.item("Superscript");
    try {
    var myName = myXMLElementSuper.name;
    }
    catch (myError){
        var myXMLElementSuper = myDocument.xmlElements.add({markupTag:"Superscript", xmlContent:mySuperscript[i]});}
    

    Any help would be greatly appreciated!

    Regards and thanks in advance.

    Julian

    The myDocument.xmlElements always has a single element - the root element.

    If you want your element directly below that, you have to work a level down.

    To try-catch for such situations regular aid is bad because you spend so usually the ESTK option stop on exceptions and real problems don't miss. Use the isValid property.

    var rootXE = myDocument.xmlElements.item(0);
    var superXE = rootXE.xmlElements.itemByName("Superscript");
    if( !superXE.isValid )
      superXE = rootXE.xmlElements.add(...
    else
     superXE = superXE.getElements()[0]; // take first of potentially multiple elements
    
  • Can a Xquery return a concatenated string and an XML element

    Hello

    My Xquery fucntion is illustrated below:

    It accepts parameters of Channel 4 and a XML element i.e., $Message which is a component of XML (application to come to the service) and I need to connect all this information in a log file.

    I use the below fucntion concat to get a concatenated string of all parameters, but for $Message I m not able to get the XML load. How to achieve the same in the XQuery?

    *$Message is the below XML file:*

    payload of <>
    < aa > a < /aa >
    < bb > two < /bb >
    < cc > 3 < /cc >
    < / payload >

    My Xquery function is:

    declare function xf:XformLog($Name_as_xs:string,)
    $id as XS: String.
    $Context as XS: String.
    $Annotation as XS: String.
    $Message as element (*))
    as XS: String {}
    Concat ("name = ', $Name, ','," Id = ", $id,", ","Message = ", $Context,","context", Annotation = ", $Annotation,","," event Message = ', data ($Message/@*, $Message / node ()) "" "")
    };


    I am trying to achieve the following log:

    Name = xyz, Id = 111, Message Contact is abc, Annotation = ggg, the event Message = < payload >
    < aa > a < /aa >
    < bb > two < /bb >
    < cc > 3 < /cc >
    < / payload >


    How can I achieve the same. Please suggest.

    Thanks in advance.

    Published by: user9223904 on March 18, 2013 03:16

    Hello

    You must use a serialization function to convert a string of the instance of the element.
    This type of functionality is not included in the XQuery standard, but many directors provide an extension to do this.

    For example, in OSB, you can use fn - bea: serialize().

    What is your environment and XQuery engine?

  • How to obtain the page to an XML element?

    Hi all

    I am fairly new to InDesign scripting (and scripts in general) and have lots of fun :-)

    I have an InDesign document containing several frames (texts, graphics, etc.) and I tagged using the InDesign tags window.

    After much struggle, I managed to get the name of the XML element tag first in my document using this simple code:

    app.activeDocument.xmlElements[0].xmlElements[0].markupTag.name
    

    I know that it worked because I got the right answer in the Javascript console. (By the way, can someone explain to me why I write xmlElements [0] twice?) And what is the difference between xmlElements and xmlItems? Any help is appreciated).

    Then I'll probably use a loop for for each markupTag of each xmlElement. But I have a lot of trouble to obtain the page associated xmlElement :-/

    After a lot of searching on Google, I came across this article which is supposed to answer my question exactly. I tried to understand this code, copy and paste in ExtendScript, but I must admit it's a bit too complex for me...

    Can someone tell me how to get a graphic or a text linked to my XML tags block? Any help is greatly appreciated!

    Nevermind, I found an easier way to achieve what I was trying to do. Actually, I wanted to be able to handle different images in my document, so why I wanted to use the XML markup.

    For those of you who have the same problem, who knows from InDesign CS5, there is an itemByName method that allows you to select an image by its name in the layers panel. So much easier to use :-)

    Thread closed!

  • How to find the page number of an xml element

    Hi everyone, sorry for my very bad English (french guy! logic). I hope you see what I'm looking for.

    I'm script (javascript), of each articles export a script from a script multiple indesign pages.

    In fact, I might have one or more article in a single file, each of which is a separate xml element. for each, I export an xml file named with, first, page where appears the xml element, the second number, the number of exported article.

    I am the second goal of success, but not the first.

    Someone has an idea?

    Hi kazegonzo,

    Please try the js code below, I have access to the doc/article/the title tag because the doc not placed in pages, you placed the title tags to access the title tag and get the page number.

    var myDoc=app.activeDocument;
    var root = myDoc.xmlElements[0];
    var docTag = root.evaluateXPathExpression('//doc//article//titre');
    for(i=0; i
    

    THX,

    csm_phil

    Post edited by: csm_phil

Maybe you are looking for

  • HP Pavilion dv6000 will not contribute to that.

    I have a HP Pavilion dv6000 for some years, and suddenly, he will supply any.  I don't know that something happens at all when I press the power button.  What's weird is that when I connect the power, the LED AC (the one with the lightning bolt above

  • What does the Setup CD?

    Hi all. About to buy a few routers, I was asked to evaluate the Linksys WRT310N. I opened the box and the first thing he says is "the installation cd. There is no explanation of what can make the software, or any information that would encourage me t

  • Vista will not read the disc, MPEG-2

    Hello. I recorded a few tv programs with my dvd burner, and it always does to the MPEG-2 format. But when I pop the disk in my laptop, windows does not detect the file, it detects the drive but please nothing to her which means that it wont let me co

  • Windows Media Player cannot play the file because the required video codec is not installed on your computer

    Windows Media Player cannot play the file because the required video codec is not installed on your computer can help me is it you pls with this.i am unable to find.where can I download codec windows media player video

  • Hard Drive crashed - Photo files stored on another drive - from Sync

    My hard drive crashed, but I had almost all of the photos and a recent catalog on a backup disk file.I have gone to the catalog of photos and press on the "!" icon to find the picture on the new drive. It reconnects only pictures of this shoot.At thi