开发者

Access and manipulate XML file using DOMDocument

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 = n开发者_JAVA技巧ew 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(); 
}


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜