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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

XML Question

  • 29-09-2013 9: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 Posts: 2,013 ✭✭✭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