Try to search your question here, if you can't find : Ask Any Question Now ?

Edit and save simple XML by php

HomeCategory: stackoverflowEdit and save simple XML by php
pragati asked 2 weeks ago

I found this script and it works, but I would like to edit all the children, not just the first one.
It’s possible?

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<?php
$xml = new DOMDocument('1.0', 'utf-8');
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->load('file.xml');

//Get item Element
$element = $xml->getElementsByTagName('global')->item(0);

//Load child elements
$name = $element->getElementsByTagName('data')->item(0);


//Replace old elements with new
$element->replaceChild($name, $name);

?>

<?php
if (isset($_POST['submit']))
{
$name->nodeValue = $_POST['namanya'];
htmlentities($xml->save('index_messages_en.xml'));

}

?>

<form method="POST" action=''>
<p><?php echo $name->nodeValue  ?></p><input type="text-name" value="<?php echo $name->nodeValue  ?>" name="namanya" />
<input name="submit" type="submit" />
</form>

The format of my xml documents is :

<global>

  <data name="title"><![CDATA[data1]]></data>
  <data name="author_name"><![CDATA[data2]]></data>

<global>

Thanks
Mau

1 Answers
Best Answer
Jyoti answered 2 weeks ago
Your Answer

12 + 9 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com