XML element to wanted position in content text?

Hi,
I am using java's XML document builder (javax.xml.parsers.*)....
is it possible to create XML element to wanted position in content text, such as:
<mycontent>
Here comes text <AndHereIsElementInWantedPosition ... /> and the normal text does continue.
Here comes text (2) <AndHereIsElementInWantedPosition ... /> and the normal text (2) does continue.
</mycontent>
I see only Element::appendChild(), and Element::setTextContent() functions, but it seems it's not possible with those functions.
and if it's possible, what functions I should use to read Elements & their position from content text? (Node class doesn't tell the position).

is it possible to create XML element to wanted position in content textYes. Text is just another kind of node. You can interleave Elements with Text nodes. The Elements aren't 'inside' the text, they are beside it, as sibling nodes.
I see only Element::appendChild(), and Element::setTextContent() functions, but it seems it's not possible with those functions.Should be. Just append children, Text nodes or Elements.
and if it's possible, what functions I should use to read Elements & their position from content text?You don't. You read the child nodes from the parent element. Some of them will be Text nodes, some of them will be Elements.

Similar Messages

  • How to map more than one xml element with some Paragraph in a Text Frame

    Hi friends,
    I am new in InDesign Java Scripting and I have to place or map, more than one xml elements of different parents, into one textbox. Is it possible through JavaScript? Can anyone help me in this because I have no idea how it should work and it urgently required.
    Thanks in Advance

    I had answered to you already in your first post: the short answer is that it's not possible on the same text box unless you assign a common ancestor of these two "parents" item. That's not a question of scripting, it's the way Indesign handle the XML with the layout. Import a xml in Indesign and drop tags to page item. What you can do manually is quite representative of what can be done through scripting.
    If you assign this anscestor to the text frame, you have to expect that all text child items will be displayed in the text frame (including the text of all the child of the two "parents" and all the other parents/childs that could be under the common ancestor). Having a XML that is designed for Indesign usage is pretty much inevitable if you are doing anything "serious".

  • How can I get content of  xml elements?

    Hello everybody,
    here is my xml document and my code which parses xml. I want to print content of all elements from xml to console but result is only null. But names of all elements shows correctly. Where is problem? Thank you in advance
    XMLSample.java
    import java.io.File;
    import java.io.IOException;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    public class XMLSample {
         private void getAttribute(Document doc) {
    NodeList list = doc.getElementsByTagName("*");
    for (int i=0; i<list.getLength(); i++) {
    // Get element
    Element el = (Element)list.item(i);
    System.out.println(el.getNodeName());
    System.out.println(el.getNodeValue());
         private Document executeXML(String[]argv) {
              if (argv.length != 1) {
                   System.err.println("Usage: java DomEcho filename");
                   System.exit(1);
              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              Document doc = null;
              try {
                   DocumentBuilder builder = factory.newDocumentBuilder();
                   doc = builder.parse(new File(argv[0]));                         
              } catch (SAXException sxe) {
                   // Error generated during parsing)
                   Exception x = sxe;
                   if (sxe.getException() != null)
                        x = sxe.getException();
                   x.printStackTrace();
              } catch (ParserConfigurationException pce) {
                   // Parser with specified options can't be built
                   pce.printStackTrace();
              } catch (IOException ioe) {
                   // I/O error
                   ioe.printStackTrace();
              System.out.println("doc > " + doc);
              return doc;
         public static void main(String argv[]) {
              XMLSample dom = new XMLSample();
              Document doc = dom.executeXML(argv);
              dom.getAttribute(doc);
    library.xml
    <library>
    <book>
    <author>
    Jan Zitniak
    </author>
    <title>
    JSP Guru
    </title>
    </book>
    <book>
    <author>
    Jan Zitniak
    </author>
    <title>
    JSP Guru
    </title>
    </book>
    </library>

    If you have XML like:
    <target>value</target>What you actually have in DOM is:
    Element
       TextCall getFirstChild() on the Element and cast the result as Text. Then call getNodeValue() on the Text node.
    - Saish

  • I need to find all XML elements and add a line break to the text of each of them

    I need to find all XML elements and add a line break to the text of each of them.
    Is this possible with a script?

    I need to go from this ...
    to this...
    but looking for the XML elements (not paragraphs) and then adding text ...
    Thanks for your attention !!!

  • XML Element of XML Element of XML Element (and so on...)

    Here is my XML data (shorted, in a file myFile):
    <LiveData>
    <Voltage>
    <Total>
    <VoltageNow>1052</VoltageNow>
    </Total>
    </Voltage>
    <Power>
    <Total>
    <PowerNow>345</PowerNow>
    </Total>
    </LiveData>
    I would like to get the VoltageNow and PowerNow values, but the following script does not work:
    tell application "System Events"
    set elem1 to XML element 1 of XML file myFile /*<LiveData>
    set power to XML elements of elem1 whose name is "Power"
    set total to XML elements of power whose name is "Total"
    set powernow to value of XML elements of total whose name is "PowerNow"
    end tell
    Error: System Events got an error: Can’t make {} into type string.
    BTW, I don't want to use XML Element X because the order may change.
    What is the correct method to traverse these elements to obtain values?

    AppleScript can handle the strings, but the System Events XML Suite doesn't work with text strings - it deals with the XML objects, which have name and value properties. The handler can be modified to show the names of an element, but it is just designed to work with the XML Suite.
    The contents of an XML file is just text, so you can forgo System Events and just use regular text manipulation statements, or use another tool such as the Satimage XMLLib osax, which is much more robust and does include commands to display the XML object as a string.
    By the way, my original handler was designed and tested in Leopard, but I discovered a Snow Leopard bug that alters the way it returns array/list contents. The following script has changes that return the functionality, in addition to a dialog handler that will display lists:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    font-weight: normal;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px; height: 340px;
    color: #000000;
    background-color: #DAFFB6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    on run -- example
    set XMLFile to (choose file without invisibles)
    show("element value:", (getXMLElement from {XMLFile, "LiveData", "Voltage", "Total", "VoltageNow"}))
    end run
    to show(label, something)
    show an alert for something, formatting lists and records
    parameters - label [text]: the alert text
    something [mixed]: an item to put in the alert message
    returns nothing
    if something is not in {null, missing value} then
    try -- show the message
    if (class of something) is in {list, record} then (something as number) -- force an error
    display alert label message (something as text)
    on error errorMessage -- lists and records don't format very well, so cheat
    set {here, there} to {(offset of "{" in errorMessage), -(offset of "}" in (reverse of text items of errorMessage) as text)}
    display alert label message text here thru there of errorMessage
    end try
    else
    display alert label message "*null or missing value*"
    end if
    end show
    to getXMLElement from XMLItems
    get the specified element from a simple XML structure by name or index
        the number of items is not fixed, but must be at least 2 (the XML file and an XML element)
      parameters: XMLItems [list] -
    item 1 [text]: the XML file path (Finder or POSIX)
    item 2 [mixed]: the XML element name or index (names are case sensitive)
    item(s) 3+ [mixed]: sub item(s)
    returns [list]: value of the element
    try
    if (count XMLItems) is less than 2 then error "getXMLElement handler:  item list contains too few items"
    tell application "System Events"
    set theXMLData to contents of XML file ((the first item of XMLItems) as text)
    -- get text of theXMLData
    set theXMLElement to XML element 1 of theXMLData -- start at the root element
    repeat with anItem in rest of XMLItems -- add on the sub items
    set anItem to contents of anItem
    try
    set anItem to anItem as integer -- index number?
    end try
    set theXMLElement to (get XML element anItem of theXMLElement)
    end repeat
    try -- return the element(s)
    -- return name of XML elements of theXMLElement
    set theResult to value of theXMLElement -- SL built-in result variable does not get set
    if theResult is missing value then error -- SL does not error on empty or missing value
    return theResult
    on error errorMessage number errorNumber -- the element is empty, or a list of items
    log errorMessage
    return value of XML elements of theXMLElement
    end try
    end tell
    on error errorMessage number errorNumber
    log errorMessage
    -- return null
    error "getXMLElement handler:  element not found (" & errorNumber & ")"
    end try
    end getXMLElement</pre>

  • [AS][CS4] How to get XML element of grep find result?

    Hi,
    Does anyone know how to get the xml element of a grep find result?
    I have multiple text frames, each containing multiple paragraphs. Each paragraph can contain one or more different xml tagged pieces of text.
    Using a simple search function I can locate the text I need, but how do I retreive the xml element applied to that piece of text.
    Using the "associated XML element" property, it doesn't work.
    set find what of find grep preferences to "€( )*(\\d)*"
    tell active document
              set myResult to find grep
              set myItem to item 1 of myResult
              set myElement to associated XML element of myItem
              -- The last line throws an error
    end tell
    The find result will return a collection of text objects.
    Thanks
    John

    Well I found this post that answered my question
    http://forums.ni.com/t5/LabVIEW/how-to-get-records​et-from-database/m-p/1471374?requireLogin=False

  • [CS5-5.5][JS] Replace xml element content with user selection

    Hi,
    I'm trying to write a script that replaces xml element content with a user selection.
    I have document containing a textframe with a "root" tag attached. In this frame I have 2 paragraphs, each tagged with a different tag.
    I would like to replace the content of one of the paragraphs with the content of a text selection.
    This piece of code doesn't seem to work:
    myXMLElement.xmlContent = app.selection[0];
    The problem is that almost all properties of the xmlelement (paragraphs, words, etc) are read-only.
    Does anyone have any suggestion?
    Thanx

    It depends on whether you want to maintain formatting. You can use
    myXMLElement.contents = app.selection[0].contents;
    in the (unlikely?) event that you don't mind blowing away the formatting. Otherwise you'll want to use something like:
    myXMLElement.xmlContent.remove();
    app.selection[0].duplicate(LocationOptions.AT_BEGINNING, myXMLElement.xmlContent);
    Jeff

  • How to separate XML element content

    Hi All,
    How can i separate XML element content in to two strings, where each string will be copied into new variables.
    For ex:
    The input I get is
    <XmLElement>C:/documents/sharedFiles/apple.pdf</XMLElement>
    now I want to break the content into two parts like
    <aaaa>C:/documents/sharedFiles/</aaaaa>
    <bbbbb>apple.pdf</bbbbbb> ( I want to separate file name from the string)
    and now I want to copy this into two other variables. How can I achieve this in BPEL. Appreciate your help.
    Thanks,
    Edited by: kameshb on Mar 25, 2013 11:16 AM

    I am getting the following error
    <bpelFault><faultType>0</faultType><subLanguageExecutionFault xmlns="http://schemas.oracle.com/bpel/extension"><part name="summary"><summary>XPath expression failed to execute. An error occurs while processing the XPath expression; the expression is substring(bpws:getVariableData('inputVariable','payload','/ns1:Tinput/ns1:URL'),1, oraext:last-index-within-string(bpws:getVariableData('inputVariable','payload','/ns1:Tinput/ns1:URL'),'/') -1) . The XPath expression failed to execute; the reason was: internal xpath error. Check the detailed root cause described in the exception message text and verify that the XPath query is correct. </summary></part><part name="code"><code>XPathExecutionError</code></part></subLanguageExecutionFault></bpelFault>
    This is the code inside XPATH
    <assign name="BreakURL">
    <copy>
    <from expression="substring(bpws:getVariableData('inputVariable','payload','/ns1:Tinput/ns1:URL'),1, oraext:last-index-within-string(bpws:getVariableData('inputVariable','payload','/ns1:Tinput/ns1:URL'),'/') -1) "/>
    <to variable="outputVariable" part="payload"
    query="/ns1:Toutput/ns1:Location"/>
    </copy>
    <copy>
    <from expression="substring(bpws:getVariableData('inputVariable','payload','/ns1:Tinput/ns1:URL'),1, oraext:last-index-within-string(bpws:getVariableData('inputVariable','payload','/ns1:Tinput/ns1:URL'),'/'),) "/>
    <to variable="outputVariable" part="payload"
    query="/ns1:Toutput/ns1:Filename"/>
    </copy>
    </assign>

  • How to find associated text frame with XML element?

    Hello experts, I am new to InDesign CS SDK and have a question.
    I am building an Extension to import an XML document into an InDesign template. As the content in XML can be unpredictable, in the Extension, I want to loop through all the XML elements and make sure it has associated text frames, and if it doesn't, I want to create a text frame and set the content to the text frame.
    I think I figured out how to create a new text frame in page and set the content in the frame, but I am having difficulty finding an associated text frame for an XML element.
    If anyone has a sample code finding a text frame for an XML element, I appriciate it. Or if anyone can tell me what document I need to look, it will be great too.
    Thanks,

    Here's a code snipet with null checks removed:
    UID MyClassName::GetFrameForXMLElement(IIDXMLElement* inXMLElement)
        InterfacePtr< ITextModel > textModel( Utils< IXMLUtils >()->QueryTextModel( inXMLElement ) );
        InterfacePtr< IFrameList > frameList( textModel->QueryFrameList() );
        UID aFrameUID = frameList->GetNthFrameUID( 0 );
        return aFrameUID;

  • Selecting the content of XML element CS3(JS)

    Hi
    I am trying to select the whole content of XML Element.
    I am trying like this
    app.activeDocument.xmlElements[i].select();
    But it is not working.
    Regards
    Suresh

    A few hints:
    Perhaps your variable
    i i
    is not defined. If that's the case, give up trying to write code for this complicated job! XML is not the easiest part of ID to begin with. Starting with uninitialized variables and flagging that as an error (and complaining about that in a forum) is a beginners' blunder.
    If I run your script line with i set to 0, the first element of my XML structure is selected. I can see with my own eyes it works, because I have the XML Structure pane in ID open. If I click on the 2nd element there and run your script line, the top (= 0th) element is selected. Perhaps you didn't open the XML Structure view so you did not see it worked after all. Or perhaps you expected something
    i else
    to be selected -- the text content, maybe -- so you tag it as "error". That's a misinterpretation of what the XmlElement object is. Understandable, but still not an error. You can have lots of XmlElements without any text or other object associated. If it was your intention to select whatever the xml element contains, try working with the property 'xmlContent'. From its description I gather that sort-of does this alternative interpretation, i.e., you can select the
    i text
    which is pointed to by the element. Untried. But do read on.
    If I run your script with i = 1, I
    i do
    get an error, and it's perfectly valid too! "Object is invalid" -- well, of course it is. There is no other XML element at that level. An app.document.xmlelements entry always points to the
    i root
    of the XML, and you can only have one. Perhaps you expected #1 to be the next sub-element. Well, not so in the ID implementation -- as usual for almost all XML based structures, it's a tree. The "next" element is xmlElements[0].xmlElements[0], which you can check by changing your line to
    >app.activeDocument.xmlElements[0].xmlElements[0].select();
    and verifying the 2nd element from the top is selected in the XML Structure view.

  • Can't import content with '&' in XML element

    I encountered the following error msg when importing the sample XML with '&' in content of an element(for example, a URL with '&' for parameters):
    <?xml version = '1.0'?>
    <ROW_List>
    <ROW>
    ...... <D3_STRU_URL>http://www.ncbi.nlm.nih.gov/mmdbsrv.cgi?form=6&db=t&Dopt=s&uid=14422
    </D3_STRU_URL>
    Error msg said:
    <Line 19, Column 78>: XML-0100: (Fatal Error) Expected ';'.
    <Line 19, Column 78>: XML-0250: (Fatal Error) Missing entity 'db'.
    <Line 19, Column 85>: XML-0100: (Fatal Error) Expected ';'.
    <Line 19, Column 85>: XML-0250: (Fatal Error) Missing entity 'Dopt'.
    <Line 19, Column 91>: XML-0100: (Fatal Error) Expected ';'.
    <Line 19, Column 91>: XML-0250: (Fatal Error) Missing entity 'uid'.
    It seems that '&' is used by XDK for a kind of special purpose.
    Does anybody know how to handle the problem if I really want to import content with '&'?
    Thanks a lot for your help.
    Yihua

    The "&" character is part of the reserved word content.
    Just like: <, &, >, ", ' to use these in an XML file you should
    use:
    <     <
         >&#8220;     &quot;
    &#8216;     &apos;
    like: This is worth < $250K
    will become: This is worth < $250K
    Willem

  • Adding text to parentStory destroys XML element / JavaScript, InD CS4

    Dear scripters,
    I'm currently stuck with this problem:
    - I'm writing text to text frames on a layout page
    - while writing some characters/strings are XML tagged (I'm creating an element)
    - I can do this only once, because adding more text after I have created an XML element destroys the link to the element
    Here's my sample:
    var MyBox = app.activeDocument.textFrames.add();
    MyBox.geometricBounds = ["0pt","0pt", "200pt", "200pt"];
    //Fill some content into the text frame
    MyBox.parentStory.contents = "bla";
    //create a xml element for some of the text
    app.activeDocument.xmlElements.item(0).xmlElements.add("test1", MyBox.parentStory.characters.itemByRange(1, 2));
    //so far so good...
    //now some calculating
    var result = "456";
    //add result to the text frame
    //doing this destroys the link to the existing xml element
    MyBox.parentStory.contents += result;
    //doing this creates a new xml element with the wrong characters selected and linked
    app.activeDocument.xmlElements.item(0).xmlElements.add("test2" , MyBox.parentStory.characters.itemByRange(4, 2));
    Can someone please help on?
    Best regards,
    TYPO

    Hello Harbs,
    thank you, it almost works now; the xml element brackets are not destroyed anymore.
    The only problem I have now is that the second element becomes a  child of the first one.
    How can I force each element to  be "independent"?
    Here's the code:
    var MyBox = app.activeDocument.textFrames.add();
    MyBox.geometricBounds = ["0pt","0pt", "200pt", "200pt"];
    var MyContent = "bla";
    MyBox.parentStory.insertionPoints[-1].contents = MyContent;
    MyBox.parentStory.characters.itemByRange(-1, -MyContent.length).select();
    app.activeDocument.xmlElements.item(0).xmlElements.add("test1" ,app.activeDocument.selection[0]);
    MyContent = "456";
    MyBox.parentStory.insertionPoints[-1].contents = MyContent;
    MyBox.parentStory.characters.itemByRange(-1, -MyContent.length).select();
    app.activeDocument.xmlElements.item(0).xmlElements.add("test2" ,app.activeDocument.selection[0]);
    Best regards,
    TYPO

  • XML Element of selected text

    Hi,
    I need to get the tag name of bold applied in InDesign document.  When finding bold contents in InDesign document using Find Options, its select bold contents with some hidden text (tags) as shown in the below image.  If i use "select in structure" of selected text, its select wrong element (parent of all selected elements).  I need to get the correct XML Element of selected text (Except hidden character).  How can i get the element of selected text??
    Can anyone help me.
    - Sudha K

    Hi,
    I need to get the tag name of bold applied in InDesign document.  When finding bold contents in InDesign document using Find Options, its select bold contents with some hidden text (tags) as shown in the below image.  If i use "select in structure" of selected text, its select wrong element (parent of all selected elements).  I need to get the correct XML Element of selected text (Except hidden character).  How can i get the element of selected text??
    Can anyone help me.
    - Sudha K

  • Content-Type of XML-Element?

    This might be a very easy question:
    Is there a possibility to find out which kind of object a certain xml-element is?
    PageItem, Movie, Sound, Graphic, Story, Text, Cell or Table
    Thanks
    Huksy

    Alright, then I get the content of the element. But how do I know the certain element is a cell?
    This didn't work:
    if(myElement[i].xmlContent == Cell) {
    alert ("Found Cell!");
    H.

  • Howto use Converting File Content in Rec. Adapt. to suppress a xml-element

    Hi,
    we use PI/700, SP6.
    I have following structure (example):
    <MsgOut>
      <Sender>Partner1</Sender>
      <Receiver>Partner2</Receiver>
      <FlatPayload>
         blabla blabla
      </FlatPayload>
    </Msgout>
    Now I wanna use a XI-File-Adapter to write just a Flat-File with the content (of the element <FlatPayload>):
        blabla blabla
    (in other words: I wanna suppress all other xml-elements beside of FlatPayload)
    But I'm not able to configurate this with the function "Converting File Content"
    I tried different possiblities:
    e.g.
    setting yyy.fieldFixedLengths = 0 and yyy.fixedLengthTooShortHandling = Cut
    (yyy = Sender and Receiver)
    or
    just defining "MsgOut,FlatPayload" as RecordSet Structure (without Sender and Receiver)
    Result: no success.
    Now my question: is it possible to suppress some xml-elements?
    Thanks for your help!
    bye
    Wolfgang

    HI,
    You can suppress the XML Nodes/Elements over here. Not Fields ..
    For e.g if your outout xml is like this
    <MsgOut>
        <Sender>Partner1</Sender>
        <Receiver>Partner2</Receiver>
    <FlatPayload>
       <flatdata> blabla blabla</flatdatat>
    </FlatPayload>
    </Msgout>
    In this case you can suppress the <FlatPayload> node/element here.. Using Cut Parameter in the Receiver File Content COnversion.
    /people/sravya.talanki2/blog/2005/08/11/solution-to-the-problem-encountered-using-variable-substitution-with-xi-sp12
    So in your case, you can restructure your data type as you required.. I have mentioned in vice-versa here
    Hope this helps,
    Regards,
    Moorthy
    Message was edited by: Krishna Moorthy P

Maybe you are looking for

  • How to load a text file int JEditorPane and highlight some words (Urgent !)

    I want to load a text file into a JEditorPane and then highlights some keywords such as while,if and else.I am using an EditorKit in order to style the JEditorPane. I have no difficulty while giving the input through the keyboard but lots of exceptio

  • Connecting a Dell monitor to macbook...

    I have a Dell monitor that's just lying around in my room. I want to use it as a "second display" for my macbook. I realized that I can't just plug it in because the cable doesn't match. I've been trying to find the appropriate cable for it, but I'm

  • Email (Gmail) query

    My gmail account wasn't working today on my iphone 4 so deleted it and set it up again. In order to sync with my 'PC' Gmail I set it up as an exchange account as per the instructions from google. Everything is working fine, but in my mailboxes the ac

  • My adobe Premiere Pro bad install!!!

    I installed the CS5 package which included adobe premiere pro CS5, but for some reason, it shows up as an icon of a blank piece of paper and an ex through it. Now this was on a Mac Book Pro with the OSX Snow Leopard...Can someone help?

  • PO 9i and designer 6i

    I can't run Designer 6i with personal Oracle 9i. What can i do ?