• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Parsing XML

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I need to parse XML response but response tags contain "xmlns=""" in them. I can parse the response if they are simple i.e. without "xmlns=""". I'm parsing them in PL/SQL. Below is sample XML response:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<LookupResponse xmlns="http://abc.net:8080/lrnsvc/">
<PhoneNumber xmlns="">2223311414</PhoneNumber>
<RoutingNumber xmlns="">2227210999</RoutingNumber>
<CallerID xmlns="">CENTER FOR ABC</CallerID>
<Location xmlns="">
<LATA xmlns="">430</LATA>
<Name xmlns="">ABCVILLE</Name>
<State xmlns="">CA</State>
</Location>
</LookupResponse>
</soap:Body>
</soap:Envelope>

If the tags are like: <PhoneNumber>2223311414</PhoneNumber>
<RoutingNumber>2227210999</RoutingNumber>

then I can parse them with below code and getting correct result.
strPhoneNo := UPPER (TRIM (SUBSTR (getValue (xmlResponseDoc2, '/PhoneNumber', strNameSpace), 1, 25)));
strRouteNo := UPPER (TRIM (SUBSTR (getValue (xmlResponseDoc2, '/RoutingNumber', strNameSpace), 1, 25)));

But if the tags are like below, I'm not sure how to parse them:
<PhoneNumber xmlns="">2223311414</PhoneNumber>
<RoutingNumber xmlns="">2227210999</RoutingNumber>

Appreciate & thanks for your help in advance.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you explain the problems you are having? Because the text you claim is a problem is simply a namespace declaration which says that the element containing it is in no namespace. This should not confuse any compliant XML parser at all.
 
Mohammed Razzack
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I try to parse below tags I'm not getting values/data out of these tags

<PhoneNumber xmlns="">2223311414</PhoneNumber>
<RoutingNumber xmlns="">2227210999</RoutingNumber>


Code to parse above tags:
strPhoneNo := UPPER (TRIM (SUBSTR (getValue (xmlResponseDoc2, '/PhoneNumber', strNameSpace), 1, 25)));
strRouteNo := UPPER (TRIM (SUBSTR (getValue (xmlResponseDoc2, '/RoutingNumber', strNameSpace), 1, 25)));

Thanks.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then apparently you're asking a question about the "getValue()" method. In which case, to solve the problem one would have to be able to look at the code of that method. If you aren't willing to post it here, then what you are looking for is something which looks for elements in the wrong namespace, I think.
 
Mohammed Razzack
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my code to parse the XML:

strPhoneNo := UPPER (TRIM (SUBSTR (getValue (xmlResponseDoc2, '/PhoneNumber', strNameSpace), 1, 25)));
strRouteNo := UPPER (TRIM (SUBSTR (getValue (xmlResponseDoc2, '/RoutingNumber', strNameSpace), 1, 25)));

This code is working fine if there is no "xmlns=""". If this (xmlns="") is there then how should I parse it?

If you want me to post all the code I can do that too. Since it's just parsing the tags where the problem is that's why I'm posting that code.

Thanks
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mohammed Razzack wrote:I'm parsing them in PL/SQL.



Well, in my opinion that was a poor decision. If you had used a proper XML parser you could just let it deal with namespaces. But now it's up to you. Personally if I inherited that code I would rewrite it in Java, or in any language which supported XML. However I suppose you're stuck with it now. So let's carry on...

I wrote:Then apparently you're asking a question about the "getValue()" method. In which case, to solve the problem one would have to be able to look at the code of that method.



You wrote:If you want me to post all the code I can do that too.



I don't know how you got the idea that I wanted to see all the code. That clearly isn't what I said. Just the getValue() method, or function, or whatever it is.

 
Mohammed Razzack
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

First of all Thank you very much for your help and I'm sorry for interpreting your suggestion wrongly.

I'll look at getValue()'s method and functions that are available.

Thanks
 
If tomatoes are a fruit, then ketchup must be a jam. Taste this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic