0
我有以下xml。Groovy使用命名空间删除部分xml
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="_0">
<u:Created>2015-10-06T15:23:32.787Z</u:Created>
<u:Expires>2015-10-06T15:28:32.787Z</u:Expires>
</u:Timestamp>
</o:Security>
</s:Header>
<s:Body>
<GetPatientTreatmentTeamResponse xmlns="urn:Custom-com:Common.2014.Services.Patient">
<GetPatientTreatmentTeamResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<CSN>422332</CSN>
<PatientIDs>
<PatientID>
<ID>23424</ID>
<IDType>type</IDType>
</PatientID>
<PatientID>
<ID>45335</ID>
<IDType>typt</IDType>
</PatientID>
</PatientIDs>
<ProviderTeam>
<ProviderTeam>
<ProviderID>1212</ProviderID>
<ProviderIDTypes>
<IDandType>
<ID>3543</ID>
<Type>type</Type>
</IDandType>
<IDandType>
<ID>4535</ID>
<Type>type</Type>
</IDandType>
<IDandType>
<ID>5353</ID>
<Type>itype</Type>
</IDandType>
<IDandType>
<ID>5353</ID>
<Type>type</Type>
</IDandType>
</ProviderIDTypes>
<ProviderName>name</ProviderName>
<ProviderRole>roler</ProviderRole>
<ProviderSpecialty/>
</ProviderTeam>
</GetPatientTreatmentTeamResult>
</GetPatientTreatmentTeamResponse>
</s:Body>
</s:Envelope>
我想要得到的是
<CSN>422332</CSN>
<PatientIDs>
<PatientID>
<ID>23424</ID>
<IDType>type</IDType>
</PatientID>
<PatientID>
<ID>45335</ID>
<IDType>typt</IDType>
</PatientID>
</PatientIDs>
<ProviderTeam>
<ProviderTeam>
<ProviderID>1212</ProviderID>
<ProviderIDTypes>
<IDandType>
<ID>3543</ID>
<Type>type</Type>
</IDandType>
<IDandType>
<ID>4535</ID>
<Type>type</Type>
</IDandType>
<IDandType>
<ID>5353</ID>
<Type>itype</Type>
</IDandType>
<IDandType>
<ID>5353</ID>
<Type>type</Type>
</IDandType>
</ProviderIDTypes>
<ProviderName>name</ProviderName>
<ProviderRole>roler</ProviderRole>
<ProviderSpecialty/>
</ProviderTeam>
我想什么做的是只使用来获取节点GetPatientTreatmentTeamResult下方的文本(这个节点将在不同的调用不同)命名空间的xmlns:I =“http://www.w3.org/2001/XMLSchema-instance(所有的呼叫都这样),并且不使用实际节点名称
我曾尝试使用XmlParser的和的XmlSlurper
。def s= new XmlSlurper(false, true).parseText(xml).declareNamespace('i':'http://www.w3.org/2001/XMLSchema-instance')
def p= new XmlParser(false, true).parseText(xml)
def ns= new Namespace("http://www.w3.org/2001/XMLSchema-instance", 'instance')
但我一直未能得到我想要的结果。
我该怎么做呢?
有没有办法让一个XML文档? – user2165673
是的,只是连载专利节点,而不是它的孩子? Soz希望你在问题中要求的washday –