Org.w3c.dom Document not parsing correctly

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moorcroft
    New Member
    • Mar 2008
    • 57

    Org.w3c.dom Document not parsing correctly

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

    Code:
    if(isPathNode(appRoot+"ExternalAddress/InternationalAddress/IntAddressLine"))
    where appRoot = //Proposal/Applicant/

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

    Code:
        private boolean isPathNode(String strPath) {
    
            return(isXPathNode(doc,strPath));
        }
    
        private boolean isXPathNode(org.w3c.dom.Node objRoot,String strPath) {
            
            try {
                org.w3c.dom.Node objNode;
    
                if(strPath.length()==0) {
                    return(false);
                }
                if((objNode=XPathAPI.selectSingleNode(objRoot,strPath))==null) {
                    return(false);
                }
    
                return(true);
            } catch(Exception e) {
                System.out.println("isXPathValue: "+e.toString());
                return(false);
            }
        }
    For some reason though this always returns false, any help??
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    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.selec tSingleNode(obj Root,strPath) ==null)

    Comment

    • moorcroft
      New Member
      • Mar 2008
      • 57

      #3
      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?

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        Yes; I would recommend using:
        if (XPathAPI.selec tSingleNode(obj Root,strPath) ==null)

        Comment

        • moorcroft
          New Member
          • Mar 2008
          • 57

          #5
          Good job cheers, its working now :-D

          Comment

          Working...