我有一个xml文件,我需要选择(而不是删除)一个特定的节点及其子节点。我知道如何去除一个和它的孩子,但不是如何删除所有的,除了这些。
输入的xml文件如下所示
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-8">
<wsse:Username>john</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<seq:Request xmlns:seq="http://schemas.mycompany.com/schema_v1_0">
<seq:StoreId>6</seq:StoreId>
<seq:Concept>2</seq:Concept>
<seq:ProductGr>
<seq:ProductGroupID>10</seq:ProductGroupID>
<seq:Seq>150</seq:Seq>
<seq:Update>1</seq:Update>
</seq:ProductGr>
</seq:Request>
</soapenv:Body>
</soapenv:Envelope>我只想获得以下代码块
<seq:Request xmlns:seq="http://schemas.mycompany.com/schema_v1_0">
<seq:StoreId>6</seq:StoreId>
<seq:Concept>2</seq:Concept>
<seq:ProductGr>
<seq:ProductGroupID>10</seq:ProductGroupID>
<seq:Seq>150</seq:Seq>
<seq:Update>1</seq:Update>
</seq:ProductGr>
</seq:Request>你能帮帮我吗?此外,名称空间的前缀可能会变化,而不是名称空间本身。
谢谢你的帮助。
发布于 2014-08-13 11:21:37
最简单的方法是
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:copy-of select="soap:Envelope/soap:Body/*[1]"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" />
</xsl:template>
</xsl:stylesheet>它将提取Body的第一个子元素,不管它的名称如何。
https://stackoverflow.com/questions/25284683
复制相似问题