$xml = new DOMDocument();
$xml_store_inventory = $xml->createElement('store-inventory'); // highest layer
$xml_item = $xml->createElement('item');
$xml_quantity = $xml->createElement('quantity');
$xml->appendChild($xml_store_inventory);
$xml_store_inventory->appendChild($xml_item);
$xml_location->appendChild($xml_quantity);
gives:
<?xml version="1.0"?>
<store-inventory>
<item>
<quantity></quantity>
</item>
</store-inventory>
So, I managed to create the above in PHP using DOM. I've been searching online on how to "populate," but I'm not finding any information on how to do this.
More specifically, I'd like this to look like this
<?xml version="1.0" encoding="UTF-8"?>
<store-inventory
xmlns="http://..."
xmlns:xsi="http://..."
xsi:schemaLocation="http://...">
<item item-id="abcd">
<quantity>0</quantity>
</item>
</store-inventory>
So, I'd like to add/change the following:
- change the XML version line to include encoding (scrape this, I figured out --> $xml = new DOMDocument('1.0', 'UTF-8');)
- Add additional information to an element. e.g. [item] to [item item-id="abcd"]
- Also [quantity] to [quantity]0[/quantity]
Can someone help me with this? TIA!