I need to load an XML source using Simple XML, duplicate an existing node with all his children, then customize an attribute of this new node before rendering XML. Any suggestion?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
SimpleXML can’t do this, so you’ll have to use DOM. The good news is that DOM and SimpleXML are two sides of the same coin, libxml. So no matter whether you’re using SimpleXML or DOM, you’re working on the same tree. Here’s an example:
If you’re doing that kind of thing a lot, you can try SimpleDOM, which is an extension to SimpleXML that lets you use DOM’s methods directly, without converting from and to DOM objects.