Xpath to select value of sibling attribute with namespace

后端 未结 3 1809
囚心锁ツ
囚心锁ツ 2020-12-20 22:41

I\'m struggling to get an XPath defined to return the value of the uniqueappversionid from the following XML:



        
相关标签:
3条回答
  • 2020-12-20 23:27

    Ok, there's probably a better approach, but this is what I've ended up using:

    //meta-data[@*='uniqueappversionid']/@*[2]
    

    I'd greatly appreciate suggestions to improve this!

    0 讨论(0)
  • 2020-12-20 23:36

    With a prefix bound to http://schemas.android.com/apk/res/android namespace:

    /manifest
       /application
          /meta-data[@a:name='uniqueappversionid']
             /@a:value
    
    0 讨论(0)
  • 2020-12-20 23:48

    Your question has as much to do with the framework in which you are executing your XPath query as with the content of the XPath query itself. For example, here's how you would do it in XSLT:

    <stylesheet version="1.0"
                xmlns="http://www.w3.org/1999/XSL/Transform"
                xmlns:android="http://schemas.android.com/apk/res/android">
      <template match="/">
        <value-of select="//meta-data[@android:name = 'uniqueappversionid']/@android:value" />
      </template>
    </stylesheet>
    

    The means of namespace setup here is through xmlns attributes on the XSLT elements under which the XPath query is nested. In a typical imperative programming language environment, you're probably more likely to have to set up namespace aliases through parameterization of the XML object(s) against which you are evaluating the query. To specify an answer for such an environment, you'd have to get specific about the XML framework.

    0 讨论(0)
提交回复
热议问题