1

I have this xml file - payload.xml

<Remoting><Response>
    <Controller id="c">
    <Messages/>
    <StructData name="Root">
        <F name="@ErrorOccured"/>
        <F name="@TransitionErrorOccurred"/>
        <List name="DataList" aspect="Delete"/>
        <List name="DataList" aspect="New">
            <Item name="001">
                <F name="CreationDateTime" >2012/04/26</F>
                <F name="ProductDescription" />
            </Item>
            <Item name="01F">
                <F name="CreationDateTime" >2012/08/09</F>
                <F name="ProductDescription" >Smartphone 16GB</F>
            </Item>                 
            <Header name="@tableSize">316 </Header>
        </List>
    </StructData>
    <Events>
        <Event event="$Core" operation="$AddRow" path="/Root/DataList"/>
    </Events>
    </Controller>
    </Response></Remoting>

I want to extract a node with particular name and particular attribute, eg.g if I want to extract

<Item name="001">
                <F name="CreationDateTime" >2012/04/26</F>
                <F name="ProductDescription" />
            </Item>

Is there any way to do it in one way without looping through all elements of .find('Item')

e.g. can I do something like .find('Item') - > attribute name = '001'

Thanks

2 Answers 2

1

Yes, you can do it using the jQuery selectors you're used to.

Demonstration (open the console to see what's logged)

Let's say your xml is in a var xmlText, you parse it using

var $xml = $($.parseXML(xmlText));

And then you find your item using

var yourItem = $xml.find('item[name="001"]'); // note the lowercase
Sign up to request clarification or add additional context in comments.

Comments

0

This tutorial may be helpful: http://www.w3schools.com/xml/xml_parser.asp Here is an example of code you could use.

xmlDoc=parser.parseFromString('<Remoting><Respon...oller>    </Response></Remoting>',"text/xml");
items = xmlDoc.getElementsByTagName('Item');
firstItem = items[0];

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.