The San Francisco PHP Meetup Group Message Board › remove comments in XML

remove comments in XML

Dave Edelhart
Posted May 8, 2010 4:52 PM
bingomanatee
San Francisco, CA
Post #: 51
Send an Email Post a Greeting
Is there an easy way to strip all comments in an xml using DOMDocument either:

* using DOMXpath
* as a setting for saveXML()

?

Thanks in advance, Dave
Scotty Logan
Posted May 9, 2010 12:23 PM
scottylogan
Stanford, CA
Post #: 1
Send an Email Post a Greeting
Try something like this:
$doc = DOMDocument::load("foo.xml");
$xp = new DOMXpath($doc);
$nodes = $xp->query('//comment()');
for ($i = 0; $i < $nodes->length; $i++) {
$nodes->item($i)->parentNode->removeChild($nodes->item($i));
}

Scotty
Powered by mvnForum

Our Sponsors

GameSpot.com

GameSpot.com & CBSi provides the facilities our group uses every month.

O'Reilly User Group Program

The O'Reilly User Group Program provides the great books we get monthly.

Other nearby
Meetup Groups
Why these groups?
x

The Meetup Groups shown here are topically similar to The San Francisco PHP Meetup Group.

Groups are more likely to be displayed here if they:

  • have a Meetup scheduled
  • have a high rating
  • have a group photo
  • are "public" and not "private"
  • have shown they are likely to stick around (older than 30 days)

Log in

  • Not registered with us yet?
or

Log in to Meetup with your Facebook account.

Sign up

or

Join this Meetup Group even quicker with your Facebook account.

By clicking the "Sign up using Facebook" or "Sign up" buttons above, you agree to Meetup's Terms of Service