Jump to content

using simpleXML


ksmatthews

Recommended Posts

HI All,

 

I am having some trouble changing an XML document with the floowing code:

 

// create XML object using XML file as parameter

$xmlobj = simplexml_load_file($folder . $XML_filename);

if($xmlobj == false)

  {

        $flag = false;

$message = "Error: XML file cannot be loaded";

  }

 

// access and modify elements

$xmlobj->sipLines->line->displayName = $dir_num; 

$xmlobj->sipLines->line->featureLabel = $dir_num;

$xmlobj->sipLines->line->authName = $dir_num;

$xmlobj->sipLines->line->authPassword = $dir_num;

 

echo $xmlobj->asXML();

 

When I execute 'echo $xmlobj->asXML();' the changes have NOT been done.

 

The path  $xmlobj->sipLines->line->displayName is correct and variable $dir_num is populated

 

Any ideas ?

 

regards,

 

Steven Matthews

Link to comment
https://forums.phpfreaks.com/topic/87242-using-simplexml/
Share on other sites

I tried to do the same thing, and here are the results:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<x>
	<y>aaa</y>
</x>
<x>
	<y>bbb</y>
</x>
</root>';

<?php
$xml = simplexml_load_file('the file above...');

echo "start: {$xml->x->y}", PHP_EOL;
$xml->x->y = 'ccc';
echo "end: {$xml->x->y}", PHP_EOL;

echo $xml->asXML();
?>

results:

start: aaa
end: ccc
<?xml version="1.0" encoding="UTF-8"?>
<root>
<x>
	<y>ccc</y>
</x>
<x>
	<y>bbb</y>
</x>
</root>

 

it seems to work fine,

maybe, if we you'll attach the XML file, i could assist you....

Link to comment
https://forums.phpfreaks.com/topic/87242-using-simplexml/#findComment-446286
Share on other sites

Thanks again,

 

I am employing your suggestions but the original input file remains the same (ie  has not changed)

I am using a linux file sytem. After running the script, when I look at the last modified time, it remains the same ...

 

Has a new output file been created, if so where ?

 

One last thing, what does $xmlobj->asXML(); actually do ?

 

regards,

 

Steven M

Link to comment
https://forums.phpfreaks.com/topic/87242-using-simplexml/#findComment-446933
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.