Here's an example using the DOMParser:

var xml = '<metric-datas><metric-data><metricPath>Application 
Infrastructure Performance|MineStar|Individual Nodes|Node 2 
9383|JMX|Test|CacheSize</metricPath><metricName>Server|Component:7|JMX|Test|CacheSize</metricName><frequency>ONE_MIN</frequency><metricValues><metric-value><startTimeInMillis>1411463700000</startTimeInMillis><value>250</value><min>250</min><max>250</max><current>250</current><sum>1750</sum><count>7</count><standardDeviation>0.0</standardDeviation><occurrences>0</occurrences><useRange>true</useRange></metric-value></metricValues></metric-data></metric-datas>';

var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xml, 'application/xml');
var metrics = xmlDoc.querySelectorAll('metric-data');

// create DataTable
var data = new google.visualization.DataTable();
data.addColumn('string', 'Metric Path');
data.addColumn('number', 'Value');

for (var i = 0; i < metrics.length; i++) {
    var path = metrics[i].querySelector('metricPath').textContent;
    var value = new 
Number(metrics[i].querySelector('value').textContent).valueOf();
    data.addRow([path, value]);
}

On Tuesday, September 23, 2014 11:03:30 PM UTC-4, Nagendra Singh wrote:
>
> Hi Andrew,
> Thanks of the reply.
> I need to put it into google api's chart table. 
> How can I handle that?
>
> On Wed, Sep 24, 2014 at 5:50 AM, Andrew Gallant <[email protected] 
> <javascript:>> wrote:
>
>> You can use the DOMParser object 
>> <https://developer.mozilla.org/en-US/docs/Web/API/DOMParser> to parse an 
>> XML document.  IE 8 does not have the DOMParser object though, so if you 
>> have to support IE 8, follow this guide 
>> <http://stackoverflow.com/questions/7949752/cross-browser-javascript-xml-parsing>,
>>  
>> or use a 3rd-party library like jQuery 
>> <http://api.jquery.com/jquery.parsexml/> to handle this for you.
>>
>>
>> On Tuesday, September 23, 2014 6:04:46 AM UTC-4, Nagendra Singh wrote:
>>>
>>> Hi, 
>>> I have xml data in following format. I need to parse only <metricPath> 
>>> and <value> and show in a UI format. I am able to parse a json data. 
>>> But how can I parse an XML data?
>>>
>>> <metric-datas>
>>>     <metric-data>
>>>         <metricPath>
>>>             Application Infrastructure Performance|MineStar|Individual 
>>> Nodes|Node 2
>>>             9383|JMX|Test|CacheSize
>>>         </metricPath>
>>>         <metricName>Server|Component:7|JMX|Test|CacheSize</metricName>
>>>         <frequency>ONE_MIN</frequency>
>>>         <metricValues>
>>>             <metric-value>
>>>                 <startTimeInMillis>1411463700000</startTimeInMillis>
>>>                 <value>250</value>
>>>                 <min>250</min>
>>>                 <max>250</max>
>>>                 <current>250</current>
>>>                 <sum>1750</sum>
>>>                 <count>7</count>
>>>                 <standardDeviation>0.0</standardDeviation>
>>>                 <occurrences>0</occurrences>
>>>                 <useRange>true</useRange>
>>>             </metric-value>
>>>         </metricValues>
>>>     </metric-data></metric-datas>
>>>
>>>  -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Google Visualization API" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/google-visualization-api/-Y_SK-TJabw/unsubscribe
>> .
>> To unsubscribe from this group and all its topics, send an email to 
>> [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at 
>> http://groups.google.com/group/google-visualization-api.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Reply via email to