How to ignore namespace when selecting XML nodes with XPath

后端 未结 2 1413
一向
一向 2020-11-29 04:37

I have to parse an XML document that looks like this:

  
 

        
相关标签:
2条回答
  • 2020-11-29 05:06

    This is FAQ (but I'm lazy to search duplicates today)

    In XPath 1.0

    //*[local-name()='name']
    

    Selects any element with "name" as local-name.

    In XPath 2.0 you can use:

    //*:name
    
    0 讨论(0)
  • 2020-11-29 05:09

    Use:

    /*/*/*/*/*
            [local-name()='REPORT_DATA' 
           or 
             local-name()='REPORT_HEADER'
            ]
    

    Anyone care for more complete syntax?

    String xPathExpression = "/*[local-name()='OASISReport]
                              /*[local-name()='MessagePayload]
                              /*[local-name()='RTO]
                              /*[local-name()='REPORT_ITEM]
                              /*[local-name()='REPORT_DATA"];
    

    Btw, if the XPath also requires the element index position:

    String xPathExpression = "/*[local-name()='OASISReport][1]
    
    0 讨论(0)
提交回复
热议问题