I'm struggling to append an child node within an XML file with a static unique ID.
The XML feed I'm working with is hosted on a server elsewhere and can only be accessed via its URL.
Said feed follows this sort of pattern:
<?xml version="1.0" encoding="UTF-8"?>
<properties>
<property>
<title>Some Sunny Place</title>
<address>Some Building, Somewhere, Really Nice</address>
</property>
<property>
<title>Some Rainy PLace Place</title>
<address>Some Gutter, Somewhere, Not So Nice</address>
</property>
</properties>
What I'm trying to achieve is using the URL from the feed is add a unique id to the 'property' node and output the XML feed at an alternate URL.
e.g. example.com/proeprty-feed contains feed without ID. Add the ID using PHP and output the feed to something.com/property-feed
<?xml version="1.0" encoding="UTF-8"?>
<properties>
<property upid=123456>
<title>Some Sunny Place</title>
<address>Some Building, Somewhere, Really Nice</address>
</property>
<property upid=abcdef>
<title>Some Rainy PLace Place</title>
<address>Some Gutter, Somewhere, Not So Nice</address>
</property>
</properties>
What I have tried is input.php
<?php
$xmlstr = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<properties>
<property>
<title>Some Sunny Place</title>
<address>Some Building, Somewhere, Really Nice</address>
</property>
<property>
<title>Some Rainy PLace Place</title>
<address>Some Gutter, Somewhere, Not So Nice</address>
</property>
</properties>
XML;
?>
And output.php
<?php
include 'input.php';
$sxe = new SimpleXMLElement($xmlstr);
$sxe->addAttribute('upid', uniqid('prop-'));
echo $sxe->asXML();
?>
But this outputs:
<properties upid="prop-5ac7c06a39ddd">
<property>
<title>Some Sunny Place</title>
<address>Some Building, Somewhere, Really Nice</address>
</property>
<property>
<title>Some Rainy PLace Place</title>
<address>Some Gutter, Somewhere, Not So Nice</address>
</property>
</properties>