9

I tring to get the attribute value from the following simple xml using my javascript.

XML :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ParentNode Symbol="$"><Row book = "test" price ="80"/></ParentNode>

jQuery: $('ParentNode').attr('Symbol');

The JQuery is working fine if the xml code is

<ParentNode Symbol="$"><Row book = "test" price ="80"/>   </ParentNode>

2 Answers 2

13

Try

var string  = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ParentNode Symbol="$"><Row book = "test" price ="80"/></ParentNode>';

var $doc = $.parseXML(string);
console.log($($doc).find('ParentNode').attr('Symbol'))

Demo: Fiddle

Sign up to request clarification or add additional context in comments.

2 Comments

@Arun P Johny, what if i have special characters in book tag. i.e <Row book = "Special `~@#$%^&*()_+-=}{|:;&apos;/.,<>? message&*()" price ="80"/>, how can i deal with them?
The fiddle's console output is '$'.
1
$(xml).find("ParentNode").attr("Symbol");

Try this

1 Comment

Hi , It returns 'undefined'

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.