Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.