File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Parsing XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Parsing XML " Watch "Parsing XML " New topic
Author

Parsing XML

Mohammed Razzack
Greenhorn

Joined: Nov 09, 2009
Posts: 7
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.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

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

Joined: Nov 09, 2009
Posts: 7
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
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

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

Joined: Nov 09, 2009
Posts: 7
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
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

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

Joined: Nov 09, 2009
Posts: 7
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parsing XML