PHP code example of pdeans / xml-builder
1. Go to this page and download the library: Download pdeans/xml-builder library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pdeans / xml-builder example snippets
use pdeans\Builders\XmlBuilder;
$bulder = new XmlBuilder;
$xml = $builder->create('Category_Add', [
'@tags' => [
'Code' => 'Tools',
'Name' => $builder->cdata('Class Tools and Skill Kits'),
],
]);
// Output: <![CDATA[Class Tools and Skill Kits]]>
echo $builder->cdata('Class Tools and Skill Kits');
// Output: 49.00
echo $builder->decimal(49.0000000);
// Output: 49.001
echo $builder->decimal(49.0005, 3);
$xml = $builder->create('CategoryProduct_Assign', [
'@attributes' => [
'category_code' => 'Food',
'product_code' => 'ale-gallon',
],
]);
$xml = $builder->create('CategoryProduct_Assign', [
'@a' => [
'category_code' => 'Food',
'product_code' => 'ale-gallon',
],
]);
$xml = $builder->create('ProductAttribute_Add', [
'@a' => [
'product_code' => 'chest',
],
'@tags' => [
'Code' => 'lock',
'Type' => 'select',
'Prompt' => $builder->cdata('Lock'),
],
]);
$xml = $builder->create('ProductAttribute_Add', [
'@a' => [
'product_code' => 'chest',
],
'@t' => [
'Code' => 'lock',
'Type' => 'select',
'Prompt' => $builder->cdata('Lock'),
],
]);
$xml = $builder->create('Module', [
'@attributes' => [
'code' => 'customfields',
'feature' => 'fields_prod',
],
'@tags' => [
'ProductField_Value' => [
'@attributes' => [
'product' => 'chest',
'field' => 'armor_type',
],
'@value' => 'wood',
],
],
]);
$xml = $builder->create('Module', [
'@a' => [
'code' => 'customfields',
'feature' => 'fields_prod',
],
'@t' => [
'ProductField_Value' => [
'@a' => [
'product' => 'chest',
'field' => 'armor_type',
],
'@v' => 'wood',
],
],
]);
$xml = $builder->create('Order_Add', [
'@t' => [
'Charges' => [
'Charge' => [
[
'Type' => 'SHIPPING',
'Description' => 'Shipping: UPS Ground',
'Amount' => 5.95
],
[
'Type' => 'TAX',
'Description' => 'Sales Tax',
'Amount' => 2.15
],
],
],
],
]);
$xml = $builder->create('Order_Add', [
'@t' => [
'TriggerFulfillmentModules' => null,
],
]);
xml
<Category_Add>
<Code>Tools</Code>
<Name><![CDATA[Class Tools and Skill Kits]]></Name>
</Category_Add>
xml
<Order_Add>
<Charges>
<Charge>
<Type>SHIPPING</Type>
<Description>Shipping: UPS Ground</Description>
<Amount>5.95</Amount>
</Charge>
<Charge>
<Type>TAX</Type>
<Description>Sales Tax</Description>
<Amount>2.15</Amount>
</Charge>
</Charges>
</Order_Add>
xml
<Order_Add>
<TriggerFulfillmentModules />
</Order_Add>