Re: What is the best way to parse XML? (414 Views)
Reply
Regular Advisor
AlexGg
Posts: 86
Registered: ‎08-10-2006
Message 1 of 7 (431 Views)

What is the best way to parse XML?

I am wondering if OO has some easy way to parse simple XML file, or string?

E.g.

<tops>
 <items>
  <item>
   <buser>sankesh</buser>
   <naddr>tutall</naddr>
  </item>
 </items>
</tops>
All I need is get result like:

buser=sankesh

naddr=tutall

 

I know I can strip all content by something, but looking for ready way.

Thanks.

 

Please use plain text.
Frequent Advisor
Lucian-Revnic
Posts: 30
Registered: ‎09-22-2011
Message 2 of 7 (426 Views)

Re: What is the best way to parse XML?

Hello Alex,

 

Have you tried to use the XPath Evaluator or XPath Query operations?

Other useful XML operations are located under XML Processing folder.

 

Hope it helps,

Lucian

Please use plain text.
Regular Advisor
AlexGg
Posts: 86
Registered: ‎08-10-2006
Message 3 of 7 (419 Views)

Re: What is the best way to parse XML?

Oh, Thanks
Please use plain text.
Trusted Contributor
ntt00015
Posts: 91
Registered: ‎09-18-2011
Message 4 of 7 (414 Views)

Re: What is the best way to parse XML?

Hi,

 

If there is any namespaces in your xml, you can not parse your xml string. I am not sure but OO9.02(with content patches 9_00_06) uses XPATH 1.0 version for XPATH evaluator. If you want to parse XML with namescapes first you should remove the namespaces from xml string using regular expression.

 

Regards. 

Please use plain text.
Regular Advisor
AlexGg
Posts: 86
Registered: ‎08-10-2006
Message 5 of 7 (407 Views)

Re: What is the best way to parse XML?

Thanks. So, thus to parse entire XML I have to know the structure of it, right?

How about get it parsed without such knowledge?

Other words: if XML is some config file of something, is it possible at all to get all variables and its values?

Please use plain text.
Trusted Contributor
ntt00015
Posts: 91
Registered: ‎09-18-2011
Message 6 of 7 (405 Views)

Re: What is the best way to parse XML?

It does not matter if it's a config file or a return string from  webservice. You can get all values if you know the structure(I mean paths).

In your example you didn't have any XMLnamespaces. So you don't have to bother yourself about it. But if the config file have the XMLnamespaces firstly you should parse it with regular expressions(via perl/javascript) and then use the output string in OO XML Operations(Thats how I do in my xml operations).

 

I am waiting for the new patch for JSON format, so hopefully I will be parsing any XML string in OO without using workarounds.

Please use plain text.
Regular Advisor
AlexGg
Posts: 86
Registered: ‎08-10-2006
Message 7 of 7 (403 Views)

Re: What is the best way to parse XML?

Thanks! Sounds good to me too now.

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation