0

I have a xml file. I want to parse it and get the text in the tags.

For example I want to extract "2.6" from the tag infoModelversion. "echo=hi hello" from the tag ns:description .

My xml file is as shown below.

<ns:workflowInvoked 
        xmlns:ns="http://airavata.apache.org/schemas/wft/2011/08" 
        infoModelVersion="2.6">
        <ns:notificationSource 
            ns:serviceID="Workflow1_cbc2c80b_511c_4a5b_9f88_fa789378296b" 
            ns:experimentID="Workflow1_cbc2c80b-511c-4a5b-9f88-fa789378296b" />
        <ns:timestamp>2013-07-26T23:45:37.654+05:30</ns:timestamp>
        <ns:description>echo=hi hello</ns:description><ns:annotation />
        <ns:initiator ns:serviceID="Workflow1_cbc2c80b_511c_4a5b_9f88_fa789378296b" />
</ns:workflowInvoked>

I was trying to parse it using the following code.

var new_var = $(xml).find("ns:workflowInvoked infoModelVersion").text();
console.log(new_var);

I am not getting proper output. Can anybody point out what mistake I am making?

1

1 Answer 1

0
var new_var = $(xml).attr("infoModelVersion");
console.log(new_var);
4
  • How will get description. var new_var = $(xml).attr("ns:description"); doesnt work
    – v09
    Commented Jul 26, 2013 at 21:42
  • var description = $(xml).find("ns\\:description").text(); Do you at least try to understand code you are using???
    – A. Wolff
    Commented Jul 26, 2013 at 21:47
  • In var description = $(xml).find("ns\\:description").text(); you are escaping the colon using // . I thought of it but did not do it as it is already enclosed in "" .
    – v09
    Commented Jul 26, 2013 at 22:11
  • ya, escaping semi colon
    – A. Wolff
    Commented Jul 26, 2013 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.