嗨,我在XML对象中缺少属性

时间:2018-07-24 09:22:07

标签: php simplexml

我在XML对象中缺少属性。

XML字符串

$xmlString1 ='<?xml version="1.0" encoding="utf-8"?>
<Response Status="0" Message="OK" >
  <Result Index="1">
    <Users>
      <User Id="id-1" ChangeDate="2017-04-05T09:41:00">
        <Details>
          <Name>Name-1</Name>
          <Position Latitude="47.0000" Longitude="11.000000" />
          <Active>true</Active>
        </Details>
        <Documents>
          <Document Id="Id-1-doc-1" Type="Image"  Width="800" Height="600">
            <Names>
              <Translation Language="de">Bild Id-1-doc-1</Translation>
              <Translation Language="en">Pic Id-1-doc-1</Translation>
            </Names>
            <URL>images/id-1-doc-1.jpg</URL>
          </Document>
          <Document Id="id-1-doc-2" Type="Image"  Width="800" Height="600">
            <Names>
              <Translation Language="de">Bild Id-1-doc-2</Translation>
              <Translation Language="en">Pic Id-1-doc-2</Translation>
            </Names>
            <URL>images/id-1-doc-2.jpg</URL>
          </Document>
        </Documents>
      </User>
    </Users>
  </Result>
</Response>';

$ xml = simplexml_load_string($ xmlString1);

我获得了Position和Document的属性,但没有Translation的属性。

位置

public 'Position' => 
  object(SimpleXMLElement)[7]
    public '@attributes' => 
      array (size=2)
         'Latitude' => string '47.0000' (length=7)
         'Longitude' => string '11.000000' (length=9)

姓名翻译

public 'Names' => 
  object(SimpleXMLElement)[11]
     public 'Translation' => 
       array (size=2)
         0 => string 'Bild Id-1-doc-2' (length=15)
         1 => string 'Pic Id-1-doc-2' (length=14)

有人知道为什么吗? 哇,我能获得语言属性吗?

0 个答案:

没有答案