SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: read xml,php

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    read xml,php

    I have a xml like this bellow,how can I read the elements and attributes?
    I can find a guide.
    Dimis
    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?> 
    <epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"> 
        <response> 
            <result code="1000"> 
                <msg>Command completed successfully</msg> 
            </result> 
            <resData> 
                <domain:chkData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd"> 
                    <domain:cd> 
                        <domain:name avail="0">dimis.gr</domain:name> 
                        <domain:reason>In Use.</domain:reason> 
                    </domain:cd> 
                </domain:chkData> 
            </resData> 
            <extension> 
                <extdomain:resData xmlns:extdomain="urn:ics-forth:params:xml:ns:extdomain-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ics-forth:params:xml:ns:extdomain-1.0 extdomain-1.0.xsd"> 
                    <extdomain:comment ref="dimis.gr">In Use.</extdomain:comment> 
                </extdomain:resData> 
            </extension> 
            <trID> 
                <clTRID>ABC:ics-forth:1079698712682</clTRID> 
                <svTRID>20090603-113421576-577-gr</svTRID> 
            </trID> 
        </response> 
    </epp>

  2. #2
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use SimpleXML class and xpath and you can easily read the result with it.

    For example, first instantiate the SimpleXMLElement class:

    $oXML = simplexml_load_string($string); // $sting is your entire XML string

    then to get a value of <clTRID> you would do this:
    $aResult = $oXML->xpath('/epp/response/trID/clTRID');
    and finally get value of it like this:
    $val = $aResult[0]

    And here are the links for you:

    http://us3.php.net/manual/en/functio...oad-string.php

    http://us3.php.net/manual/en/functio...ment-xpath.php
    Last edited by lampcms.com; Jun 3, 2009 at 04:44. Reason: fixed misspelled 'response' in xpath


Bookmarks

Posting Permissions

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