Jump to content

XML ignoring comments


jvs37

Recommended Posts

Hi all,

 

I have another uestion. I am currently working with an XML document that has some comments in it that need to stay however it is messing up my parser that I am working on. How can I get around this issue and make the php parser ignore the comments? here is a snippet of the code I am working on.

 

php

//open XML file containing data for current slide

$currentslidefilepath = "slides/xml/";
$currentslidefilepath .= $slides[$currentslide];
$currentSlideXml = simplexml_load_file($currentslidefilepath);

 

 

XML

<!-- there are some comments here -->

 

<Basic>

        <another>some data</another>

</Basic>

 

Link to comment
https://forums.phpfreaks.com/topic/232319-xml-ignoring-comments/
Share on other sites

Are the XML comments causing the simplexml_load_file function to fail?  If so, you could just read the contents of the XML file with fopen, strip out the comments with regex, and then use simplexml_load_string to return the object instead of simplexml_load_file.

 

However, if simplexml_load_file isn't failing, and instead it's a matter of whatever parser you are writing, I would work more on getting that to ignore the comments instead of using the method I described, since it would be significantly faster.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.