XPath in SimpleXML for default namespaces without needing prefixes

后端 未结 3 473
逝去的感伤
逝去的感伤 2020-12-09 20:59

I have an XML document that has a default namespace attached to it, eg



        
3条回答
  •  借酒劲吻你
    2020-12-09 21:17

    In order to avoid hacks like the str_replace one you have there (and I would recommend avoiding that), you can run the XML files through an XSLT to strip out the namespace:

    
      
    
      
        
          
        
      
    
      
        
          
        
      
    
    

    When run on either of these inputs:

    
      
        
      
    
    
    
      
        
      
    
    

    The output is the same:

    
      
        
      
    
    

    This would allow you to use your prefix-less XPaths on the result.

提交回复
热议问题