【发布时间】:2014-08-13 11:14:37
【问题描述】:
我有一个 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>
你能帮帮我吗?此外,命名空间的前缀可以变化,尽管命名空间本身不会变化。
感谢您的帮助。
【问题讨论】: