How to access XML elements by name in Extendscript??

I'm almost done the script that I've been working on, but something has been nagging me since I started. When I did start, I looked at the JS Tools Guide CS5 that comes with the extendscript ide to check how to access XML elements, children, attributes etc. It says this:
The XML object represents an XML element node in an XML tree. The topmost XML object for an XML file
represents the root node. It acts as a list, which contains additional XML objects for each element. These in
turn contain XML objects for their own member elements, and so on.
The child elements of an element tree are available as properties of the XML object for the parent. The
name of the property corresponds to the name of the element. Each property contains an array of XML
objects, each of which represents one element of the named type.
So basically it converts the XML into JSON. And you can access the properties like so:
<book category="COOKING">
     <title lang="en">The Boston Cooking-School Cookbook</title>
     <author>Fannie Merrit Farmer</author>
     <year>1896</year>
     <price>49.99</price>
</book>
The Javascript statement bookstoreXML.book; returns the entire list of books.
The statement bookstoreXML.book[0]; returns the XML object for the first book.
The statement bookstoreXML.book[0].author; returns all authors of the first book.
A couple pages down it talks about Retrieving contained elements using children(), elements(), descendants().
So now I look through the XML Object properties and I see that I can use:
xmlObj.child (which) which A String, the element name, or a Number, a 0-based index into this node’s child array.
or
xmlObj.descendants ([name])
name Optional. A String, the element name to match. If not provided, matches all
elements.
or
xmlObj.elements (name);
name Optional. A String, the element name to match. If not provided, matches all
elements.
This is an excerpt of an XML I was working with:
<ROW xmlns="http://www.filemaker.com/fmpdsoresult"
     MODID="16"
     RECORDID="11128">
   <Sign_Type>251.dr</Sign_Type>
   <fm:Location xmlns:fm="http://www.filemaker.com/fmpdsoresult" xmlns="">5-5024</fm:Location>
   <Line1>Zone
Floor
3
Patient Rooms
R532 - R436 even
Patient Rooms
R522 - R446 even
Xavier Elevators
Zone
Patient Rooms
R537 - 5757 odd
Main Elevators
Zone</Line1>
</ROW>
Extendscript will not give me an anything when I try to access elements by name. Instead I have to access by index, which works, but I'd rather search for names!
Actually the console log returns: <![CDATA[]]>
What am I doing wrong!?

First, those E4X XML objects are definitely no JSON (plain data) - they have a multitude of methods, even for tasks that would easily be implemented as property (e.g. the length() function), and they also bind xml element and attribute names onto the objects, allowing to target a multitude of XML nodes with a single statement. Or did you mean your script with that "it"?
Anyway, as you found out the ExtendScript XML object handles namespaces mostly by hiding them from you.
You could play around with global namespace settings, see the JavaScript tools guide.
You could also explicitly specify a namespace. This works for me:
$.writeln(myXML["fm:Location"]);
For simple use I had most success with a brute force approach that just strips the namespaces.
function removeAllNamespace(xml)
          var ns =new Namespace();
          var d=xml.descendants();
          for (var i=0;i<d.length();i++)
    d[i].setNamespace(ns);

Similar Messages

  • How to access xml file using c

    how to access xml file using c. are there any libraries regarding xml fastinfoset in c? Please let me know about any resources if u know? thanks!!!
    samitha

    There are different methods to access XML data which have pro's and cons. Let us know more about what you want to do and we can help you.

  • How to access the element s in a hashMap with order

    Does anybody know how to access the elements in a hashMap with order.
    I know set is a collection that doesn't gaurantee the order so the iterator of keySet will not gaurantee the order.
    Is there any way to solve this?
    Thanks

    If you mean the order in which the key/value pairs where added to the
    map, have a look at the LinkedHashMap class. If you mean 'natural'
    order, you shouldn't be using a HashMap at all then; have a look at the
    TreeMap class instead.
    kind regards,
    Jos

  • XML element name contains (.) periods, how to access each element value?

    Hi All,
    This is the xml that needs to be processed.
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <com.companyx>
    <person>
    <employee.data>
    <employee.name>mrx</employee.name>
    <employee.number>1001</employee.number>
    </employee.data>
    <employee.data>
    <employee.name>mry</employee.name>
    <employee.number>1002</employee.number>
    </employee.data>
    <employee.data>
    <employee.name>mrz</employee.name>
    <employee.number>1003</employee.number>
    </employee.data>
    <page>0</page>
    </person>
    </com.companyx>
    Please tell me how to access the <employee.name> value of
    the first <employee.data> element.
    An early help is much appreciated.......
    Thanks in Advance,
    Vijay Karthik

    Give this a try... should do the trick
    trace(myXML.person["employee.data"][0]["employee.name"])

  • How to refer ?XML element tag name? in the RTF variable

    Hi All,
    I want to declare variable and assign the value of XML element tag to that variable.
    Following are the steps:
    <?xdoxslt:set_variable($_XDOCTX, MYCOUNT,1)?>
    <?xdoxslt:get_variable($_XDOCTX, MYCOUNT)?>
    <?if: xdoxslt:get_variable($_XDOCTX, MYCOUNT) =1?>xxx<?end if?>
    In the declaration part,I need to replace 1 with some of the xml element tag value(for example : <?vendor_name?>).
    But when I try to do so,I get some list of exceptions.
    Please suggest how to proceed.
    Thanks and Regards,
    Kaveri

    Hi Pradeep,
    Thanks for your response.Here my requirement goes:
    for -each:
    text(database value)
    end for-each
    This text value will continue from page 1 to N.
    So for page1 I want HEADER1 and from page2 onwards,I require different header HEADR2.
    By using your approach,my text which needs to be continued on different pages will not be acheived.
    One more thing I got from XMLP User guide:
    <xdofo:inline-total
    display-condition="exceptfirst"
    name="InvAmt">.
    SInce all my tags are generated from Oracel reports,I am unable to use the above xml line.Is there any way to use this by modifying the syntax..
    Please let me know your suggestions since this is show stopper for my report.
    Thanks and Regards,
    Kaveri

  • How to access an element using its name or id if it is not a class variable?

    I am trying to retrieve the element I added to my UI in a different  function. I am using actionscript 3. I know I can put the variable into a  class variable, so it can be access anywhere in the class, but I have  too many elements. Is there anyway I could access them without putting  them into class variable?
    Thanks.
    public class Test extends SkinnableContainer{
    // private var image:Image; <-- I try not to do this, too messy
    private function func1() {
        var image:Image = new Image();
        addElement(image);
    private function func2() {
        var image:Image = /* how to get the element from my UI without putting into class variable */

    Here is what works for me:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx"
                   creationComplete="init()"
                   minWidth="955" minHeight="600">
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <fx:Script>
            <![CDATA[
                import spark.components.Image;
                private var  image:Image;
                private function init():void
                    image = new Image();
                    addElement(image);
                    trace(this["image"]);
            ]]>
        </fx:Script>   
    </s:Application>

  • JDOM - Accessing XML Elements

    I have an XML file which have multiple element with same tag but different attribute. If I want to access a specific element with the require attribute, at the moment, I access every element and check it's attribute. Is there a way/method to get an element with the required attribute directly using JDOM

    ehm..
    Can you show how I have to do to get an element from a Xml file using Jdom and Xpath?
    my xml file is like this:
    <catalog>
        <param1>
              <name> XXX </name>
              <price> YYY </price>
        </param1>
        <param2>
              <name> EEE </name>
              <price> RRR </price>
        </param2>
        <param3>
              <name> TTT </name>
              <price> GGG </price>
        </param3>
    </catalog> tnx & bye

  • How to make XML element used in RTF PRIVATE/PUBLIC ? I know how to hide columns in RTF, but dont know how to generate the xml in below way. Please help.

    Hi
    I am following below link to hide/show my columns dynamically. See "Column Formatting"
    http://docs.oracle.com/cd/E12844_01/doc/bip.1013/e12187.pdf
    As per doc, element can be made private/public.
    <items type="PUBLIC">
    <item>
      <name>Plasma TV</name>
      <quantity>10</quantity>
      <price>4000</price>
    </item>
    <item>
    And same can be used to hide the column using condition
    <?if@column:/items/@type="PUBLIC"?>
    MY QUESTION IS HOW TO DO THIS IN MY XML BELOW?
    Below is part of my XML code which I am using in Data Definition for RTF.
    <group name="GH3" source="QH3">
    <element name="COLUMN_HEAD3" value="COLUMN_NAME" />
    </group>
    <group name="GH4" source="QH4">
    <element name="COLUMN_HEAD4" value="COLUMN_NAME" />
    </group>
    I am getting output like this.
    <LIST_GH3>
    <GH3>
    <COLUMN_HEAD3>REBILL_TO_OTHER_BUSINESS_UNIT</COLUMN_HEAD3>
    </GH3>
    </LIST_GH3>
    <LIST_GH4>
    <GH4>
    <COLUMN_HEAD4>XYZ</COLUMN_HEAD4>
    </GH4>
    </LIST_GH4>
    In order to use logic as per oracle document I want output like this.
    <LIST_GH3 type="PUBLIC">
    <GH3>
    <COLUMN_HEAD3>REBILL_TO_OTHER_BUSINESS_UNIT</COLUMN_HEAD3>
    </GH3>
    </LIST_GH3>
    <LIST_GH4 type="PRIVATE">
    <GH4>
    <COLUMN_HEAD4>BLANK</COLUMN_HEAD4>
    </GH4>
    </LIST_GH4>
    What changes I need to make in my XML code to get the runtime output as above? Please help. Where do i need to make changes in the above xml? Group name? Element name?
    I am planning to use below condition in RTF template to hide the column,  but dont know how to set the type of column as PRIVATE/PUBLIC in the XML output used to populate data in the RTF at runtime.
    <?if@column:/BTSPIEXP/LIST_GH3/@type=”PUBLIC”?>COLUMN_HEAD3<?end if?>
    Regards,
    Swapnil K.

    Hi,
    Issue has been resolved. I used the value of the element to determine to display it or not.
    Regards,
    Swapnil K.

  • How to access XML attributes with JSTL

    Hello,
    I'm using the XML functions of JSTL. I'm trying to parse the following RSS feed.
    http://weather.yahooapis.com/forecastrss?p=USNY0996
    I can get it parsed and access the elements via JSTL, but is it possible to access the attributes of some of the elements?
    For example, how can I get the city attribute out of
    <yweather:location city="New York" region="NY" country="US" />

    Hello,
    I'm using the XML functions of JSTL. I'm trying to parse the following RSS feed.
    http://weather.yahooapis.com/forecastrss?p=USNY0996
    I can get it parsed and access the elements via JSTL, but is it possible to access the attributes of some of the elements?
    For example, how can I get the city attribute out of
    <yweather:location city="New York" region="NY" country="US" />

  • 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 iterate xml elements using PL/SQL

    Hello,
    Let's say I have the following xml:
    <A>
    <B name="b1">
    </B>
    <B name="b2">
    </B>
    </A>
    I would like to iterate over the B and sub-B elements using PL/SQL?
    Any help will be appreciated.

    Hi,
    You can use 'PL/SQL DOM API for XMLType (DBMS_XMLDOM)'
    to work with XML. You can check the example present at
    http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/appdev.920/a96620/xdb08pls.htm#1041419
    to check how it does.
    The API for the package DBMS_XMLDOM is given on the same page(http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/appdev.920/a96620/xdb08pls.htm#1040676)
    You can use them for your requirement.
    Regards,
    Anupama

  • How to create XML element with out creating a document

    I ve been looking for hours for a method to create an XML element without the need for the Document. I am trying to create objects that access the database, and I need in each of these objects a method that returns only an element (ie. getXMLData()). And in the class that created these object, I nee to call the getXML() methods and construct a document. However, I am not looking to create the document if I am not going to use it. In the component class I need to be able to traverse the xml element and read and modify the values. Is there a way to do so with sun's JDK ?

    I ve been looking for hours for a method to create an
    XML element without the need for the Document.
    ... I am not looking to create the document if I
    am not going to use it.Hi M-A,
    Though you have been told the solution, let's stick to your original issue, just for the sake of interest. I gather what you have in mind is finding the answer to the following question: is there a way of creating a document without having to bind it to any data source? The answer is yes. What you might need is the createDocument() method of the DOMImplementation interface which offers lightwight document handling by obviating the need to construct a particular DOM instance. (You could also use the getDOMImplementation() method of the DOMImplementationRegistry interface, but it has bugs.) Here's a sample code:DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser = factory.newDocumentBuilder();
    DOMImplementation domImpl = parser.getDOMImplementation();
    Document doc = domImpl.createDocument(null, "rootnode", null);The above code produces the following document:<?xml version="1.0" encoding="UTF-8"?>
    <rootnode/>You can make this document even skinnier if you pass null values to all three parameters of the createDocument() method, in which case the document will only contain the prolog. I think both the creation and the structure of this document are simple enough for you to use it as some sort of utility (e.g. by putting the code in a separate class) for creating elements.

  • How to access XML files inside IDML?

    Hi All,
    How to access the different XML files like designmap, story, masterspread, etc. found inside the IDML files?
    Pl. help.
    Thanks,
    Praveen

    An External Library DC is only intended to include jars. Using a Java DC may be a better idea, unless you put your xml files into a jar first (but you'd need a Java DC for that...).

  • [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

  • Newbee: How to access fields with duplicated names?

    How can i access fields where the name already exists (Like FieldName[0], FieldName[2],...) - and where else can i get answers to simple questions like this one?
    Fieldname[n].thisValue does not work.
    Thanks for help.

    xfa.resolveNode("FieldName["0"]") etc.. I think should work

Maybe you are looking for

  • Ipod connected but not recognized

    When I connect my ipod it charges but is not recognized by itunes. Usually when I have something connected to the usb port it has a little icon on my toolbar on the bottom of my screen...that doesn't happen with this. For some reason I think I select

  • Is it possible to add a field in Attachment screen?

    Hello Exports, I wan to know is it possible to add a  customer field in Attachment screen (Project, RFx,MA, A) . As there are a lots of attachments added in normal working in various documents like project,MA,RFX etc, so whether can add a field  to c

  • Lion in App Store problem

    Hi! I'm coming because I want to do a fresh intall of Lion. I have a Mac Mini mid-2011 and came with Lion instaled. Yes, I know, ML is coming, but right now I will going to wait to maybe 10,8,2. Fine, the problem is, trying to download Lion, in the A

  • Hyperion smarttview

    Heyy, Gurus !!! Please guide me : I am trying to access in substitution variable in Smartview . using below macros for accessing substituion variable from application But am getting Compile Error while executing the below script That is* Compile Erro

  • Trying to download a trial of Photoshop Elements but can't download Air

    My husband has suggested getting a better photo editing software and I saw Photoshop Elements and thought about buying it.  I see that you are able to download a trial version but I don't have AIR.   When I go to download it it just keeps opening up