0

I am trying to use DOMDocument to access an XML file, find data that matches a certain criteria, and then drop the node containing it if it does. I then need to create a new XML file with the remaining data.

Below is the function I am using, with $current_balances being the full path to the XML file that i wish to use. I am looking for a specific transaction date (which I will change to a variable one this is working), and if that date is found then I need to drop the node that is associated with that date.

The porblem though is that I keep getting the following error, and I cannot figure out why -

Warning: DOMDocument::loadXML() [domdocument.loadxml]: Start tag expected, '<' not found in Entity, line: 1

I hope that makes sense, and I hope someone is able to help.

Thanks.

function get_xml_data($current_balances = null){
 $doc = new DOMDOcument; 
 $doc->loadxml($current_balances);

 $xpath = new DOMXpath($doc); 
 foreach($xpath->query('//data[record/LastAccountsTransactionDate="2010-10-08"]') as $node) { 
  $node->parentNode->removeChild($node); 
 } 
 echo $doc->savexml(); 
}

1 Answers1

0

The XML loading seems to be the root of your problem, and determining which part of the XML file is triggering the error.

If you can confirm that a BOM in the file is not to blame, see this: What would cause DOMDocument.load to fail loading XML from a URL that is accessible?

Community
  • 1
  • 1
bcosca
  • 17,371
  • 5
  • 40
  • 51
  • Thanks for the reply. I have now discovered load and save, as opposed to loadxml and savexml, so I am now able to get in to the document and then save it as another. The only bit I am not sure on now is how to cycle through each date, check that it is not older than 6 months (180 days) and remove it if it is. – David Gard Oct 21 '10 at 14:53