为什么 simpleXML 不将此 xml 转换为可用的内容?
我正在尝试使用 PHP 中的 Web 服务。我无法控制网络服务的输出。它给了我看起来不错的 XML,但 simpleXML 只是返回一个空对象给我。这是从 web 服务返回的 XML,
<?xml version="1.0" encoding="utf-8"?>
<DataSet xmlns="http://Service">
<xs:schema id="WorkOrders" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="WorkOrders" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="WorkOrder">
<xs:complexType>
<xs:sequence>
<xs:element name="WorkOrder_x0023_" type="xs:string" minOccurs="0" />
<xs:element name="DateEntered" type="xs:string" minOccurs="0" />
<xs:element name="DateCompleted" type="xs:string" minOccurs="0" />
<xs:element name="DateChanged" type="xs:string" minOccurs="0" />
<xs:element name="Status" type="xs:string" minOccurs="0" />
<xs:element name="Type" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<WorkOrders xmlns="">
<WorkOrder diffgr:id="WorkOrder1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
<WorkOrder_x0023_>7164724</WorkOrder_x0023_>
<DateEntered>07/19/11</DateEntered>
<DateCompleted>07/21/11</DateCompleted>
<DateChanged>07/21/11</DateChanged>
<Status>CP</Status>
<Type>IN</Type>
</WorkOrder>
</WorkOrders>
</diffgr:diffgram>
</DataSet>
这是通过我的脚本中的简单 $xml = file_get_contents($url);
调用获得的。 simplexml_load_string($xml);
返回一个空对象。
(object) SimpleXMLElement Object
(
)
我知道我在这里遗漏了一些东西,但我就是无法指出它。有什么想法吗?
I am attempting to consume a webservice in PHP. I have no control over the output of the webservice. It gives me what looks like good XML but simpleXML just returns an empty object back to me. Here is the XML that is returned from the webservice
<?xml version="1.0" encoding="utf-8"?>
<DataSet xmlns="http://Service">
<xs:schema id="WorkOrders" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="WorkOrders" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="WorkOrder">
<xs:complexType>
<xs:sequence>
<xs:element name="WorkOrder_x0023_" type="xs:string" minOccurs="0" />
<xs:element name="DateEntered" type="xs:string" minOccurs="0" />
<xs:element name="DateCompleted" type="xs:string" minOccurs="0" />
<xs:element name="DateChanged" type="xs:string" minOccurs="0" />
<xs:element name="Status" type="xs:string" minOccurs="0" />
<xs:element name="Type" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<WorkOrders xmlns="">
<WorkOrder diffgr:id="WorkOrder1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
<WorkOrder_x0023_>7164724</WorkOrder_x0023_>
<DateEntered>07/19/11</DateEntered>
<DateCompleted>07/21/11</DateCompleted>
<DateChanged>07/21/11</DateChanged>
<Status>CP</Status>
<Type>IN</Type>
</WorkOrder>
</WorkOrders>
</diffgr:diffgram>
</DataSet>
This is being obtained by a simple $xml = file_get_contents($url);
call in my script.simplexml_load_string($xml);
returns an empty object.
(object) SimpleXMLElement Object
(
)
I know I'm missing something here but I just cant put my finger on it. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在访问命名空间子项和 diffgram(以及 WorkOrder 的 id)等属性时,您需要指定命名空间。尝试:(
这些子元素回到默认名称空间中)
参考:http://blog.sherifmansour.com /?p=302
You need to specify the namespace when accessing namespaced children and attributes like diffgram (and the WorkOrder's id). Try:
(those child elements are back in the default namespace)
Reference: http://blog.sherifmansour.com/?p=302