SitePoint Sponsor

User Tag List

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

    xdom,xpath problem

    I have to read the xml below with this code
    Code:
    $doc = new DOMDocument('1.0');
    $doc->loadXML( $te) or die('error');
    echo $doc->savexml();
     
    $xpath = new DOMXPath($doc);
    $arts = $xpath->query("/epp/response/result/msg");
     
    foreach ($arts as $art) 
    {
        echo $art->nodeValue."<br />";
    }
    But the xpath code does not work what is wrong?How can I read the domain:name for exampe?
    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="1">dimis.gr</domain:name>
                    </domain:cd>
                    <domain:cd>
                        <domain:name avail="0">cdl.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">The domain can be provisioned.</extdomain:comment>
                    <extdomain:comment ref="cdl.gr">In Use.</extdomain:comment>
                </extdomain:resData>
            </extension>
            <trID>
                <clTRID>ABC:ics-forth:1079698712682</clTRID>
                <svTRID>20090604-122933743-828-gr</svTRID>
            </trID>
        </response>
    </epp>

  2. #2
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I set this
    Code:
    <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">
    as
    <epp>
    and this worked
    Code:
     $xpath = new Domxpath($doc);
    $result = $xpath->query("//msg");
    foreach ($result as $node) {
        print $node->nodeName ."\n";   
    }
    The page had some warnings also (Namespace prefix domain on reason is not defined etc).
    So the problem is the xmls etc at code,how can I solve it?
    Dimis

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2009
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Easier to do with simpleXML:

    PHP Code:
    $epp simplexml_load_file('sample.xml');
    $epp->registerXPathNamespace('domain''urn:ietf:params:xml:ns:domain-1.0');

    $result $epp->xpath('//domain:name');

    foreach (
    $result as $name) {
      echo 
    $name "<br />";


  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2009
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To do using DOM:

    PHP Code:
    $xml file_get_contents('sample.xml');

    $dom = new DOMDocument();
    $dom->loadXML($xml);

    $xpath = new DOMXpath($dom);

    $xpath->registerNamespace("domain""urn:ietf:params:xml:ns:domain-1.0");

    $stuff $xpath->evaluate("//domain:name");
    foreach (
    $stuff as $st) {
      echo 
    $st->firstChild->data;
      } 


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
  •