【发布时间】:2012-02-20 15:35:06
【问题描述】:
我对我的客户进行 SOAP 调用。它以字符串形式返回 XML 文档(这是我无能为力的解决方法)。我有一个变量中的 XML,我需要读取这个 XML 来获取我想要的信息。
我正在寻找DomesticCustomer、Addresses 和GridOwner 的字段。我想如果有人帮助我到达DomesticCustomer-part,我可以自己完成剩下的工作。
注意:在这个例子中,每个字段下只有一个条目,但可能有多个,所以我需要能够foreach这个。
注意 #2:因为我使用的客户端有一些奇怪的解决方法,所以响应(xml)是一个简单的字符串。
XML 是:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<MeteringPointIdResponse xmlns="http://www.ediel.no/schemas/public/nubix/MeteringPointIdResponse">
<RequestId xmlns="">3423424234</RequestId>
<Requestor xmlns="">
<GLN>234234234</GLN>
</Requestor>
<Customers xmlns="">
<DomesticCustomer>
<LastName>Name</LastName>
<FirstName>Name</FirstName>
<BirthDate>xxx-xx-xx</BirthDate>
<MeterNumber>xxxxx</MeterNumber>
<Addresses>
<Address>
<Address1>345345</Address1>
<PostCode>3514</PostCode>
<Location>xxxxxx</Location>
<CountryCode>xx</CountryCode>
<Installation>
<Description>xxxxx</Description>
<MeteringPointId>xxxxxxxxxxxxxxx</MeteringPointId>
<MeteringMethod>xxxxxx</MeteringMethod>
<InstallationStatus>xxxx</InstallationStatus>
<LastReadOffDate>xxxx-xx-xx</LastReadOffDate>
</Installation>
<GridOwner>
<GLN>xxxxxxx</GLN>
<Name>xxxxxxxx</Name>
<ProdatAddress>
<InterchangeRecipient>
<Id>xxxxxxx</Id>
<Qualifier>xx</Qualifier>
<Subaddress>xxxxx</Subaddress>
</InterchangeRecipient>
<Party>
<Id>xxxxxxxxxx</Id>
<CodeListResponsible>xxxx</CodeListResponsible>
</Party>
<EDISyntax>
<CharSet>xxx</CharSet>
<SyntaxId>xxxx</SyntaxId>
</EDISyntax>
<SMTPAddress>test@hey.com</SMTPAddress>
</ProdatAddress>
</GridOwner>
</Address>
</Addresses>
</DomesticCustomer>
</Customers>
</MeteringPointIdResponse>
</soap:Body>
</soap:Envelope>
【问题讨论】:
-
你有没有看我的问题?这是关于读取我在变量中的 XML 文档。尽可能远离相关。
-
那怎么不是重复的呢?使用 SimpleXML 加载变量,然后您可以如图所示访问它。除了如何解析和处理 XML 之外,SOAP 或 HTML 的回答太频繁了,以至于没有另一个问题询问如何从 XML 文档中获取
<randomElement/>。您的问题中没有任何具体内容可以证明不关闭它是合理的。只需查看右侧的相关部分。