0

before

<root>
 <child1>child1</child1>
 <child2>child2</child2>
 <child3>child3</child3>
</root>

I want the following result(after)

<root>
 <child1>child1</child1>
 <child3>child3</child3>
</root>

I'm using PHP and SimpleXML. How to skip a element on PHP?

hakre
  • 193,403
  • 52
  • 435
  • 836
freddiefujiwara
  • 57,041
  • 28
  • 76
  • 106
  • Are you looking to re-print the modified XML document or do you just want to be able to parse 1 child element? Are you trying to parse only the first child element or remove the last child element? Your question is not very clear. – user183037 Feb 14 '11 at 07:18
  • thank you for answering . I wanna remove the child2 element. please give me a solution – freddiefujiwara Feb 14 '11 at 07:21
  • Has been answered before: http://stackoverflow.com/search?q=remove+element+with+simplexml+php. Please point out why none of these help solve your problem. – Gordon Feb 14 '11 at 08:07
  • possible duplicate of [A simple program to CRUD node and node values of xml file](http://stackoverflow.com/questions/4906073/a-simple-program-to-crud-node-and-node-values-of-xml-file) – Gordon Feb 14 '11 at 08:12

1 Answers1

2

you can consider this

$str = THE_XML;
$xml = simplexml_load_string($str);
unset($xml->child2);
echo $xml->asXML);

Or refer this How to deleted an element inside XML string? (looks like duplicated)

Community
  • 1
  • 1
ajreal
  • 46,720
  • 11
  • 89
  • 119
  • any reason why you dont closevote when you know that it's a duplicate and another duplicate is already given in the comments? Why answer again? – Gordon Feb 14 '11 at 17:34