Re: What is the best way to parse XML? (491 Views)
Reply
Regular Advisor
AlexGg
Posts: 86
Registered: ‎08-10-2006
Message 1 of 7 (519 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.

 

Frequent Advisor
Lucian-Revnic
Posts: 31
Registered: ‎09-22-2011
Message 2 of 7 (514 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

Regular Advisor
AlexGg
Posts: 86
Registered: ‎08-10-2006
Message 3 of 7 (507 Views)

Re: What is the best way to parse XML?

Oh, Thanks
Trusted Contributor
ntt00015
Posts: 91
Registered: ‎09-18-2011
Message 4 of 7 (502 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. 

Regular Advisor
AlexGg
Posts: 86
Registered: ‎08-10-2006
Message 5 of 7 (495 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?

Trusted Contributor
ntt00015
Posts: 91
Registered: ‎09-18-2011
Message 6 of 7 (493 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.

Regular Advisor
AlexGg
Posts: 86
Registered: ‎08-10-2006
Message 7 of 7 (491 Views)

Re: What is the best way to parse XML?

Thanks! Sounds good to me too now.

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.