Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    29
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Nothing returned parsing namespaced xml

    I'm trying to parse this xml. I'm not sure why it's return nothing. What am I doing wrong here:

    Code:
    $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/>";

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    you’re passing the wrong namespace. the namespace is not "ns0" but "http://www.openapplications.org/oagis".
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    29
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I tried that, but I got an error



    Code:
    $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

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    that error has nothing to do with the name of the namespace. PHP is complaining about simplexml_load_string() not returning an object.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •