Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

XML Question

  • 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, Registered Users 2, Paid Member Posts: 2,032 ✭✭✭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, Registered Users 2 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