Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

XML Question

Options
  • 29-09-2013 10:15pm
    #1
    Closed Accounts Posts: 1,930 ✭✭✭


    I am trying to create a new hook in WHMCS that every time a domain is ordered a support ticket is automatically created. I am doing it step by step as I am very much a newbie.

    So far I have the code below which returns XML

    $command = "getorders";
    $adminuser = "admin";
    $values["id"] = $vars;
    $results = localAPI($command,$values,$adminuser);
    The XML is formatted like:

    <whmcsapi>
    <action>getorders</action>
    <result>success</result>
    <totalresults>1</totalresults>
    <startnumber>0</startnumber>
    <numreturned>1</numreturned>
    <orders>
    <order>
    <id>1</id>
    <ordernum>5031802290</ordernum>
    <userid>1</userid>
    <contactid>0</contactid>
    <date>2010-01-22 18:09:02</date>
    <nameservers></nameservers>
    <transfersecret></transfersecret>
    <promocode></promocode>
    <promotype></promotype>
    <promovalue></promovalue>
    <amount>0.00</amount>
    <paymentmethod>iveri</paymentmethod>
    <invoiceid>0</invoiceid>
    <status>Active</status>
    <ipaddress>127.0.0.1</ipaddress>
    <fraudmodule></fraudmodule>
    <fraudoutput></fraudoutput>
    <notes></notes>
    <paymentmethodname>PayPal</paymentmethodname>
    <paymentstatus></paymentstatus>
    <name>A Testclient</name>
    </order>
    </orders>
    I can access $results[result] and get it displayed/emailed/processed. However, I am not sure how to access the child such as id or invoiceid?

    I think it is something like

    $results[orders.order.id]
    but I am not sure of the syntax.

    I have tried to find guides on line but failed miserably. Would anyone be able to help/direct me to guides online.


Comments

  • Registered Users Posts: 1,984 ✭✭✭lynchie


    Assuming we are talking php, as far as I remember you can create a SimpleXMLElement() like $xml = new SipleXMLElement($results) and then access it like $xml->result or $xml->orders[0]->id


  • Registered Users Posts: 3,078 ✭✭✭onemorechance


    Use XPath.
    <?php
    $string = <<<XML
    <a>
     <b>
      <c>text</c>
      <c>stuff</c>
     </b>
     <d>
      <c>code</c>
     </d>
    </a>
    XML;
    
    $xml = new SimpleXMLElement($string);
    
    /* Search for <a><b><c> */
    $result = $xml->xpath('/a/b/c');
    
    while(list( , $node) = each($result)) {
        echo '/a/b/c: ',$node,"\n";
    }
    
    /* Relative paths also work... */
    $result = $xml->xpath('b/c');
    
    while(list( , $node) = each($result)) {
        echo 'b/c: ',$node,"\n";
    }
    ?>
    

    Source: http://php.net/manual/en/simplexmlelement.xpath.php


Advertisement