PHP尝试获取简单的XML属性值

时间:2018-06-19 19:49:42

标签: php xml simplexml

这是我的XML:

<WebContent diffgr:id="WebContent1" msdata:rowOrder="0">
  <orig_inv_no>73</orig_inv_no>
  <inv_no>141</inv_no>
  <inv_type>S</inv_type>
  <content_type>3</content_type>
  <content_type_desc>Test</content_type_desc>
  <content_value>Sample content</content_value>
 </WebContent>
<WebContent diffgr:id="WebContent2" msdata:rowOrder="0">
  <orig_inv_no>73</orig_inv_no>
  <inv_no>141</inv_no>
  <inv_type>S</inv_type>
  <content_type>3</content_type>
  <content_type_desc>Test</content_type_desc>
  <content_value>Sample content</content_value>
 </WebContent>

获取节点“ WebContent”的属性“ differ:id”很麻烦

似乎不喜欢属性名称中的冒号。有任何想法吗?

2 个答案:

答案 0 :(得分:0)

属性是“ diffgr:id”而不是“ differ:id”,也许这是您的问题

答案 1 :(得分:0)

尝试一下:

$xml->WebContent->attributes("diffgr",TRUE)->id;
// TRUE means that `diffgr` is a prefix of the attribute

可以在这里找到-> https://stackoverflow.com/a/15546669/2040840

相关问题