I have an XML whose elements i need to group and display using javascript.
How can I parse the xml so that the final output would be the count of the distinct elements. i.e.
The XMlstring
txt = txt + "<FileList>";
txt = txt + "<File>";
txt = txt + "<FileID>1234</FileID>";
txt = txt + "<FileType>image</FileType>";
txt = txt + "<FileDateTime>201112345</FileDateTime>";
txt = txt + "<FileTitle>something1</FileTitle>";
txt = txt + "<FileSize>123</FileSize>";
txt = txt + "</File>";
txt = txt + "<File>";
txt = txt + "<FileID>1209</FileID>";
txt = txt + "<FileType>image</FileType>";
txt = txt + "<FileDateTime>201167890</FileDateTime>";
txt = txt + "<FileTitle>something1</FileTitle>";
txt = txt + "<FileSize>123</FileSize>";
txt = txt + "</File>";
txt = txt + "</FileList>";
Html I want to display
201112345 (1)
201167890 (1)
Any Help would be appreciated,
Thanks, bhat
You’re using jQuery so you can use that to give you easy access to your XML’s DOM.
Just instantiate a jQuery wrapper for your XML in the usual manner:
Then, find all the
<FileDateTime>children and summarize their content in an object:Then you have your summary data in
summary.Live example: http://jsfiddle.net/ambiguous/gKgyr/
UPDATE: Based on this question about XML parsing in IE, I think using
$.parseXMLwill help with IE:I can’t check right now though but here’s a live version of this one: http://jsfiddle.net/ambiguous/gKgyr/12/