0

Actually I am working on a website for which I manage the database using XML file(s). I want to update the XML file which means I want to change the text in between tags of XML file. For example my XML file structure is as follows

<books>
<book>
<Name>BookName1</Name>
<Author>author1</Author>
</book>
<book>
<Name>BookName2</Name>
<Author>author2</Author>
</book>
</books>

Now what I want to do is update the BookName1 in the Name tag to BookName2. Any tag at any node likewise. I want to do it with PHP.

2

1 Answer 1

1

Have a look at SimpleXML. You can access and change your elements like an array then:

<?php 
$string = '<books>
<book>
<Name>BookName1</Name>
<Author>author1</Author>
</book>
<book>
<Name>BookName2</Name>
<Author>author2</Author>
</book>
</books>';

$xml = simplexml_load_string($string);
$xml->book[0]->Name= "Something else"; // or BookName2
echo $xml->asXML();
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.