...

View Full Version : Nothing returned parsing namespaced xml



walker6o9
11-12-2012, 11:46 PM
I'm trying to parse this xml. I'm not sure why it's return nothing. What am I doing wrong here:


$xml = '<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-12T14:42:20.175-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>386853</ns0:PersonCode>
<ns0:PersonName>
<ns0:GivenName>Bryan</ns0:GivenName>
<ns0:FamilyName>Hickerson</ns0:FamilyName>
<ns0:UserArea/>
</ns0:PersonName>
<ns0:UserArea/>
</ns0:Person>
<ns0:qcTelex/>
<ns0:EMailAddress>bryanjh@gmail.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:PrimaryAddress>
</ns0:Addresses>
<ns0:UserArea>
<ns0:Property>
<ns0:NameValue name="reg_id">131413</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>bryanjh@gmail.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-05-24T00:00:00-07:00</ns0:ChangeDate>
<ns0:UserArea>
<ns0:Property>
<ns0:NameValue name="UPDATED_BY">thor</ns0:NameValue>
</ns0:Property>
</ns0:UserArea>
</ns0:Change>
</ns0:Status>
<ns0:DateAuthorized>2012-05-24T00:00:00-07:00</ns0:DateAuthorized>
<ns0:AuthorizationCode>CRD_AR</ns0:AuthorizationCode>
<ns0:UserArea>
<ns0:Property>
<ns0:NameValue name="CREATED_BY">thor</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>102</ns0:Id>
<ns0:Type>bus_role</ns0:Type>
<ns0:Status>
<ns0:Code>A</ns0:Code>
<ns0:Change>
<ns0:ChangeDate>2011-05-26T10:56:13-07: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>2011-05-26T10:56:12-07:00</ns0:DateAuthorized>
<ns0:AuthorizationCode>QDN</ns0:AuthorizationCode>
<ns0:UserArea>
<ns0:Property>
<ns0:NameValue name="CREATED_BY">QPIM</ns0:NameValue>
</ns0:Property>
<ns0:Property>
<ns0:NameValue name="DESCRIPTION">QDN Role</ns0:NameValue>
</ns0:Property>
<ns0:Property>
<ns0:NameValue name="TAG">qdn</ns0:NameValue>
</ns0:Property>
<ns0:Property>
<ns0:NameValue name="OWNER_ID">142</ns0:NameValue>
</ns0:Property>
<ns0:Property>
<ns0:NameValue name="OWNER_NAME">QDN_ADMINS</ns0:NameValue>
</ns0:Property>
</ns0:UserArea>
</ns0:Authorization>
<ns0:Authorization>
<ns0:Id>1</ns0:Id>
<ns0:Type>bus_role</ns0:Type>
<ns0:Status>
<ns0:Code>A</ns0:Code>
<ns0:Change>
<ns0:ChangeDate>2012-05-24T00:00:00-07:00</ns0:ChangeDate>
<ns0:UserArea>
<ns0:Property>
<ns0:NameValue name="UPDATED_BY">thor</ns0:NameValue>
</ns0:Property>
</ns0:UserArea>
</ns0:Change>
</ns0:Status>
<ns0:DateAuthorized>2012-05-24T00:00:00-07:00</ns0:DateAuthorized>
<ns0:AuthorizationCode>QPIM_DEF_ROLE</ns0:AuthorizationCode>
<ns0:UserArea>
<ns0:Property>
<ns0:NameValue name="CREATED_BY">thor</ns0:NameValue>
</ns0:Property>
<ns0:Property>
<ns0:NameValue name="DESCRIPTION">QPIM default Role</ns0:NameValue>
</ns0:Property>
<ns0:Property>
<ns0:NameValue name="TAG">default</ns0:NameValue>
</ns0:Property>
<ns0:Property>
<ns0:NameValue name="OWNER_ID">84</ns0:NameValue>
</ns0:Property>
<ns0:Property>
<ns0:NameValue name="OWNER_NAME">QPIM_BUSROLE_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>2011-05-26T10:56:19-07: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>2011-05-26T10:56:12-07: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>2011-05-26T10:56:38-07:00</ns0:ChangeDate>
<ns0:UserArea>
<ns0:Property>
<ns0:NameValue name="UPDATED_BY">qdnsrvc</ns0:NameValue>
</ns0:Property>
</ns0:UserArea>
</ns0:Change>
</ns0:Status>
<ns0:DateAuthorized>2011-05-26T10:56:12-07: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:UserAccount>
</ns0:UserArea>
</ns0:PrimaryContact>
</ns0:Contacts>
</ns0:Party>
</ns0:DataArea>
</ns0:SyncParty>';
//print '<pre>' .print_r($xml, TRUE) . '</pre>';
//$simpleXml = simplexml_load_string($xml);
$simpleXml = new SimpleXMLElement($xml);
//print print_r($simpleXml->attributes('ns0', true));
//print print_r($simpleXml->children('ns0', true)->applicationarea, TRUE);
print $simpleXml->children('ns0', true)->applicationarea->sender->creationdatetime ."<br/>";

Dormilich
11-13-2012, 07:38 AM
you’re passing the wrong namespace. the namespace is not "ns0" but "http://www.openapplications.org/oagis".

walker6o9
11-13-2012, 07:05 PM
I tried that, but I got an error




$simpleXml = simplexml_load_string($xml);
print $simpleXml->children('http://www.openapplications.org/oagis', true)->applicationarea->creationdatetime;


Call to a member function children() on a non-object

Dormilich
11-13-2012, 08:53 PM
that error has nothing to do with the name of the namespace. PHP is complaining about simplexml_load_string() not returning an object.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum