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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.