Share ideas, ask questions, and get feedback about developing for ProcessMaker
Forum rules: Please post new questions under "Developing processes & programming" for ProcessMaker 2 or 3.
By JarodC
#785326
I'm trying to parse the returning XML from a REST call to Openbravo and struggling.
If I wanted to pull out say <active> status from the response and assign to a variable, how would I parse the XML?
Thanks in advance!!

XML response except is as follows:
<ob:Openbravo xmlns:ob="http://www.openbravo.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Country id="106" identifier="Spain">
<id>106</id>
<client id="0" entity-name="ADClient" identifier="System"/>
<organization id="0" entity-name="Organization" identifier="*"/>
<active>true</active>
<creationDate transient="true">2011-02-22T17:06:39.0Z</creationDate>
<createdBy transient="true" id="0" entity-name="ADUser" identifier="System"/>
<updated transient="true">2011-02-22T17:06:39.0Z</updated>
<updatedBy transient="true" id="0" entity-name="ADUser" identifier="System"/>
<name>Spain</name>
User avatar
By giovani
#785330
Hi JarodC,

If you have an XML string like:
Code: Select all
$xmlString = '<?xml version="1.0" encoding="UTF-8"?>
<ob:Openbravo xmlns:ob="http://www.openbravo.com">
  <Invoice>
    <active>true</active>
    <organization id="E443A31992CB4635AFCAEABE7183CE85"/>
    <salesTransaction>true</salesTransaction>
    <documentType id ="7FCD49652E104E6BB06C3A0D787412E3"/>
    <transactionDocument id ="7FCD49652E104E6BB06C3A0D787412E3"/>
    <documentNo>1000050</documentNo>
    <accountingDate>2012-05-29</accountingDate>
    <invoiceDate>2012-05-29</invoiceDate>
    <currency id="102"/>
    <priceList id="AEE66281A08F42B6BC509B8A80A33C29"/>
    <businessPartner id="9E6850C866BD4921AD0EB7F7796CE2C7"/>
    <partnerAddress id="BFE1FB707BA84A6D8AF61A785F3CE1C1"/>
    <paymentTerms id="66BA1164A7394344BB9CD1A6ECEED05D"/>
    <paymentMethod id="A97CFD2AFC234B59BB0A72189BD8FC2A"/>
  </Invoice>
</ob:Openbravo>';
You just need to convert it into a Simple XML Element to pull out data.
For example, to get <active>:
Code: Select all
$xml = new SimpleXMLElement($xmlString);
@@pmVariable = $xml->Invoice->active;
I hope it helps.

Regards,
By JarodC
#785339
Thanks very much for that. Much appreciated
I thought I'd need to refer to the ID, in this case 106, as in:

$xml->Country[106]->name, but that notation doesn't work.

Incidentally, if there was more than one country node is there a way to do that? ... or do you need to iterate through all the nodes and compare against a value?

A Dream11 clone script is a pre-made software solu[…]

A stake clone script is a pre-designed, error-free[…]

The Aviator casino game script clone script replic[…]

The ZED RUN Clone Script by Dappsfirm replicates t[…]