jvs37 Posted March 31, 2011 Share Posted March 31, 2011 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 More sharing options...
nethnet Posted March 31, 2011 Share Posted March 31, 2011 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. Link to comment https://forums.phpfreaks.com/topic/232319-xml-ignoring-comments/#findComment-1195132 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.