473,322 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Org.w3c.dom Document not parsing correctly

My code parses an xml document and checks if nodes exist and contain text.

Expand|Select|Wrap|Line Numbers
  1. if(isPathNode(appRoot+"ExternalAddress/InternationalAddress/IntAddressLine"))
  2.  
where appRoot = //Proposal/Applicant/

Then in the following block of code, 'doc' is a valid xml document.

Expand|Select|Wrap|Line Numbers
  1.     private boolean isPathNode(String strPath) {
  2.  
  3.         return(isXPathNode(doc,strPath));
  4.     }
  5.  
  6.     private boolean isXPathNode(org.w3c.dom.Node objRoot,String strPath) {
  7.  
  8.         try {
  9.             org.w3c.dom.Node objNode;
  10.  
  11.             if(strPath.length()==0) {
  12.                 return(false);
  13.             }
  14.             if((objNode=XPathAPI.selectSingleNode(objRoot,strPath))==null) {
  15.                 return(false);
  16.             }
  17.  
  18.             return(true);
  19.         } catch(Exception e) {
  20.             System.out.println("isXPathValue: "+e.toString());
  21.             return(false);
  22.         }
  23.     }
For some reason though this always returns false, any help??
Jan 23 '09 #1
4 2363
jkmyoung
2,057 Expert 2GB
Namespace issue? eg: xmlns
Does it return true for any other xpath? eg. if you pass strPath as "//*" does it still return false?

Otherwise would need to see source xml.

Why are you setting the functionResult to an object? Why not just:
if (XPathAPI.selectSingleNode(objRoot,strPath) ==null)
Jan 23 '09 #2
Because I didn't write the code! The person who wrote it has left our company and it's my job to go through all his work and discover how he wrote it and where bugs are coming from!

Should this work correctly if I just do not set it as an object then?
Jan 26 '09 #3
jkmyoung
2,057 Expert 2GB
Yes; I would recommend using:
if (XPathAPI.selectSingleNode(objRoot,strPath) ==null)
Jan 26 '09 #4
Good job cheers, its working now :-D
Jan 27 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Prakash | last post by:
Hi all, I am trying a parse a xml document containing japanese text by constructing a DOMBuilder object. The document created after parsing is empty. If the xml document does not contain...
1
by: rosemm | last post by:
I am working on a project where I need to take an XML document, search through it and produce an Excel or Access file with the search results. Any suggestions for how this can be done?? I am new to...
12
by: Radek Maciaszek | last post by:
Hi It's very interesting problem. I couldn't even find any inforamtion about it on the google. I think that the best way of explain will be this simple example: <html> <body> <script...
3
by: Alexander Mikhailian | last post by:
I have an http = new XMLHttpRequest(); that provides me with an http.responseXML. Somewhere deep in the http.responseXML there is a fragment called e.g. mydom that I want to copy with all its...
10
by: Russell Mangel | last post by:
What would be the best way to parse this XML document? I want to avoid using XMLDocument. I don't know if I should use XMLTextReader, or Xpath classes. There is only one element <MessageStore>...
1
by: alex.sherwin | last post by:
Working on a google homepage module. One of the things I do is retrieve results from a search into a string. I want to be able to access all the anchors in this string, (their name, href, and...
11
by: Michael Powe | last post by:
How can I make an XHTML-compliant form of an expression in this format: document.write("<scr"+"ipt type='text/javascript' src='path/to/file.js'>"+"</scr"+"ipt>"); this turns out to be a...
10
by: Simon Brooke | last post by:
The DOM API has included public Node importNode(Node,boolean) as a method of the Document interface for a long time. Does anything actually implement it? Xerces 2 is giving me: ...
2
by: nicky123 | last post by:
Hi everyone, This is a brief description that I have provided for parsing & displaying an XML document using DOM API. Please feel free to post your own comments & views regarding...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.