Hello!
I am trying to go through an XML file and take out certain parts of it.
As seen below, the Line is a child of LineStatus. I would like to remove, say, the LineStatus block that Line ID="2" is in from the XML document. I know the format of the XML is a bit strange, but surely there is a way of doing this?
The structure of it is like this:
I am doing this in PHP and reading the file:
Thanks!
I am trying to go through an XML file and take out certain parts of it.
As seen below, the Line is a child of LineStatus. I would like to remove, say, the LineStatus block that Line ID="2" is in from the XML document. I know the format of the XML is a bit strange, but surely there is a way of doing this?
The structure of it is like this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfLineStatus xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://webservices.lul.co.uk/">
<LineStatus ID="0" StatusDetails="">
<BranchDisruptions />
<Line ID="1" Name="Name1" />
<Status ID="GS" CssClass="GoodService" Description="Good Service" IsActive="true">
<StatusType ID="1" Description="Line" />
</Status>
</LineStatus>
<LineStatus ID="1" StatusDetails="Problem to service">
<BranchDisruptions />
<Line ID="2" Name="Name2" />
<Status ID="PC" CssClass="DisruptedService" Description="Part Closure" IsActive="true">
<StatusType ID="1" Description="Line" />
</Status>
</LineStatus>
</ArrayOfLineStatus>
I am doing this in PHP and reading the file:
PHP:
$xmlstr = file_get_contents('an.xml');
$sitemap = new SimpleXMLElement($xmlstr);
foreach($sitemap->children() as $child) {
foreach($child->children() as $subchild) {
foreach($subchild->attributes() as $subchildAttr) {
if ($subchildAttr->getName() == 'Name' && ($subChildAttr != "82" || $subChildAttr != "81")) {
echo $subchild->asXML()."\n";
}
}
}
}
?>
Thanks!