重複の可能性:
SimpleXML を使用して名前空間で XML を解析する
simpleXml 文字列を解析して値を取得するのが困難です。私はもう試した
$xml = new SimpleXmlElement($simpleXml);
$xml->registerXPathNamespace("ns0", "http://www.openapplications.org/oagis");
foreach($xml->xpath('//ns0:applicationarea/a:sender') as $n) {
echo $n->creationdatetime . "success";
}
creationdatetime フィールドを取得しますが、これは何も返しません。私は単純な xml の解析に慣れていますが、名前空間付きの xml には困難が伴います。特に、すべての例に名前空間付きの xml が常に埋め込まれているためです。
このコードを試しました。
$simpleXml = simplexml_load_string($xml);
print $simpleXml->children('ns0', true)->applicationarea->creationdatetime;
print print_r($simpleXml, TRUE);
しかし、これは作成日時について何も出力しませんでした。$simpleXmlを印刷すると、これが印刷されます
SimpleXMLElement Object ( [@attributes] => Array ( [revision] => 1.0 [environment] => Production [lang] => en-US )
以下は、印刷された $simpleXml の値です。
<ns0:syncparty xmlns:ns0="http://www.openapplications.org/oagis" revision="1.0" environment="Production" lang="en-US">
<ns0:applicationarea>
<ns0:sender>
<ns0:authorizationid>QPIM</ns0:authorizationid>
</ns0:sender>
<ns0:creationdatetime>2012-11-12T09:58:32.257-08:00</ns0:creationdatetime>
</ns0:applicationarea>
<ns0:dataarea>
<ns0:sync>
<ns0:synccriteria expressionlanguage="XPath">
<ns0:syncexpression action="Sync">GetContact</ns0:syncexpression>
</ns0:synccriteria>
</ns0:sync>
<ns0:party active="false" onetime="false">
<ns0:contacts>
<ns0:primarycontact>
<ns0:person>
<ns0:personcode>409090</ns0:personcode>
<ns0:personname>
<ns0:givenname>Erik</ns0:givenname>
<ns0:familyname>Sparrow</ns0:familyname>
<ns0:userarea>
</ns0:userarea></ns0:personname>
<ns0:userarea>
</ns0:userarea></ns0:person>
<ns0:qctelex>
<ns0:emailaddress>artest02@qcomtest.com</ns0:emailaddress>
<ns0:addresses>
<ns0:primaryaddress>
<ns0:country>UNITED STATES</ns0:country>
<ns0:qccountrycode>
<ns0:qcccode>US</ns0:qcccode>
</ns0:qccountrycode>
<ns0:userarea>
</ns0:userarea></ns0:primaryaddress>
</ns0:addresses>
<ns0:userarea>
<ns0:property>
<ns0:namevalue name="reg_id">172914</ns0:namevalue>
<ns0:description>QPIM Registration Id</ns0:description>
</ns0:property>
<ns0:property>
<ns0:namevalue name="qcOldDN">N/A</ns0:namevalue>
<ns0:description>QPIM Rename Values</ns0:description>
</ns0:property>
<ns0:useraccount>
<ns0:systemid>artest02@qcomtest.com</ns0:systemid>
<ns0:authorization>
<ns0:id>422</ns0:id>
<ns0:type>bus_role</ns0:type>
<ns0:status>
<ns0:code>A</ns0:code>
<ns0:change>
<ns0:changedate>2012-02-06T11:20:34-08:00</ns0:changedate>
<ns0:userarea>
<ns0:property>
<ns0:namevalue name="UPDATED_BY">QPIM</ns0:namevalue>
</ns0:property>
</ns0:userarea>
</ns0:change>
</ns0:status>
<ns0:dateauthorized>2012-02-06T11:20:34-08:00</ns0:dateauthorized>
<ns0:authorizationcode>CRD_AR</ns0:authorizationcode>
<ns0:userarea>
<ns0:property>
<ns0:namevalue name="CREATED_BY">QPIM</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="DESCRIPTION">Provisioning Role for CRD_AR</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="TAG">ar</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="OWNER_ID">484</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="OWNER_NAME">CRD_Admins</ns0:namevalue>
</ns0:property>
</ns0:userarea>
</ns0:authorization>
<ns0:authorization>
<ns0:id>402</ns0:id>
<ns0:type>bus_role</ns0:type>
<ns0:status>
<ns0:code>A</ns0:code>
<ns0:change>
<ns0:changedate>2012-07-18T13:55:41-07:00</ns0:changedate>
<ns0:userarea>
<ns0:property>
<ns0:namevalue name="UPDATED_BY">arsrvc</ns0:namevalue>
</ns0:property>
</ns0:userarea>
</ns0:change>
</ns0:status>
<ns0:dateauthorized>2012-07-18T13:55:41-07:00</ns0:dateauthorized>
<ns0:authorizationcode>CRD_Alpha</ns0:authorizationcode>
<ns0:userarea>
<ns0:property>
<ns0:namevalue name="CREATED_BY">arsrvc</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="DESCRIPTION">Provisioning role for CRD_ALPHA</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="TAG">alpha</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="OWNER_ID">484</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="OWNER_NAME">CRD_Admins</ns0:namevalue>
</ns0:property>
</ns0:userarea>
</ns0:authorization>
<ns0:authorization>
<ns0:id>22</ns0:id>
<ns0:type>policy_role</ns0:type>
<ns0:status>
<ns0:code>A</ns0:code>
<ns0:description>Approved</ns0:description>
<ns0:change>
<ns0:changedate>2012-02-06T11:20:43-08:00</ns0:changedate>
<ns0:userarea>
<ns0:property>
<ns0:namevalue name="UPDATED_BY">QPIM_VALID_DPL</ns0:namevalue>
</ns0:property>
</ns0:userarea>
</ns0:change>
</ns0:status>
<ns0:dateauthorized>2012-02-06T11:20:34-08:00</ns0:dateauthorized>
<ns0:authorizationcode>QPIM_VALID_DPL</ns0:authorizationcode>
<ns0:userarea>
<ns0:property>
<ns0:namevalue name="CREATED_BY">QPIM</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="DESCRIPTION">This role is used to flag if a person has been DPL approved</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="TAG">dpl,validation</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="OWNER_ID">82</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="OWNER_NAME">QPIM_POLICY_ADMINS</ns0:namevalue>
</ns0:property>
</ns0:userarea>
</ns0:authorization>
<ns0:authorization>
<ns0:id>21</ns0:id>
<ns0:type>policy_role</ns0:type>
<ns0:status>
<ns0:code>A</ns0:code>
<ns0:change>
<ns0:changedate>2012-02-06T11:21:24-08:00</ns0:changedate>
<ns0:userarea>
<ns0:property>
<ns0:namevalue name="UPDATED_BY">arsrvc</ns0:namevalue>
</ns0:property>
</ns0:userarea>
</ns0:change>
</ns0:status>
<ns0:dateauthorized>2012-02-06T11:20:34-08:00</ns0:dateauthorized>
<ns0:authorizationcode>QPIM_VALID_EMAIL</ns0:authorizationcode>
<ns0:userarea>
<ns0:property>
<ns0:namevalue name="CREATED_BY">QPIM</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="DESCRIPTION">This role is used to flag if a person has been email validated</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="TAG">email,validation</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="OWNER_ID">82</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="OWNER_NAME">QPIM_POLICY_ADMINS</ns0:namevalue>
</ns0:property>
</ns0:userarea>
</ns0:authorization>
<ns0:authorization>
<ns0:id>122</ns0:id>
<ns0:type>bus_role</ns0:type>
<ns0:status>
<ns0:code>A</ns0:code>
<ns0:change>
<ns0:changedate>2012-02-06T11:24:46-08:00</ns0:changedate>
<ns0:userarea>
<ns0:property>
<ns0:namevalue name="UPDATED_BY">brewsrvc</ns0:namevalue>
</ns0:property>
</ns0:userarea>
</ns0:change>
</ns0:status>
<ns0:dateauthorized>2012-02-06T11:24:46-08:00</ns0:dateauthorized>
<ns0:authorizationcode>REG_DEV</ns0:authorizationcode>
<ns0:userarea>
<ns0:property>
<ns0:namevalue name="CREATED_BY">brewsrvc</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="DESCRIPTION">Provisioning group for Registered Developers</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="TAG">regdev</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="OWNER_ID">182</ns0:namevalue>
</ns0:property>
<ns0:property>
<ns0:namevalue name="OWNER_NAME">REG_DEV_ADMIN</ns0:namevalue>
</ns0:property>
</ns0:userarea>
</ns0:authorization>
</ns0:useraccount>
</ns0:userarea>
</ns0:qctelex></ns0:primarycontact>
</ns0:contacts>
</ns0:party>
</ns0:dataarea>