ozwolverine Posted September 28, 2006 Share Posted September 28, 2006 Hello everybody, I have this question:I need to read (load) an xml file I have on disk, so I'm reading it with something like this:[code] $xml = simplexml_load_file($this->stylesXml); [/code]Now I need to add other tags to the already existent tags, So I to get that I wrote this code:[code] //New XML Tags $documentContentTag = 'office:document-content'; $stylesTag = 'office:automatic-styles'; $styleTag = 'style:style'; $styleProps = 'style:paragraph-properties'; //Attributes (Name , value) $styleAttrName = 'style:name'; $styleAttrVal = 'P1'; $styleAttrFamName = 'style:family'; $styleAttrFamVal = 'paragraph'; $styleAttrParentName = 'style:parent-style-name'; $styleAttrParentVal = 'Standard'; $stylePropsAttrName = 'fo:break-before'; $stylePropsAttrVal = 'page'; //Add tags to existent xml $styles = $xml->$documentContentTag -> addChild($stylesTag, ''); //echo $xml->asXML(); $style = $styles -> addChild($styleTag,''); $style->addAttribute($styleAttrName, $styleAttrVal); $style->addAttribute($styleAttrFamName, $styleAttrFamVal); $style->addAttribute($styleAttrParentName, $styleAttrParentVal); $stylePropsChild = $style->addChild($styleProps,''); $stylePropsChild->addAttribute($stylePropsAttrName, $stylePropsAttrVal);[/code]What I want to create is this structure:[code]<office:automatic-styles> <style:style style:name="P1" style:family="paragraph" style:parent-style-name="Standard"> <style:paragraph-properties fo:break-before="page"/> </style:style></office:automatic-styles>[/code]in a existent tag (root tag) of the xml called: [code]</office:document-content>[/code]But I have three problems:1. I get this warning in the browser: [tt]Warning: SimpleXMLElement::addChild() [function.SimpleXMLElement-addChild]: Node no longer exists in[/tt]After the execution of the line: [code]$style = $styles -> addChild($styleTag,'');[/code] is executedWhy?2. If I try to echo the XML file (including tags), I just get literals without tags :(. How could I do it?3. If I write and XML file using something like: [code] if ($this->fp = fopen($fileName, 'w')) { $this->fileSize = fwrite($this->fp,$this->content); fclose($this->fp); }[/code]or read it in a similar way I just get literals without tagsWhat should I do?Thanks a lot. Link to comment https://forums.phpfreaks.com/topic/22385-reading-writing-xml-files-to-persistent-storage/ Share on other sites More sharing options...
ozwolverine Posted September 28, 2006 Author Share Posted September 28, 2006 Now I'm able to write the full xml structure to a file, using this code that I found in another post:[code]file_put_contents($apuntador, $xml->asXML());[/code]Now the problem is generating the XML tags, They throw me that warning message: [quote]Warning: SimpleXMLElement::addChild() [function.SimpleXMLElement-addChild]: Node no longer exists in[/quote]What is wrong in the tags generation code?thanks a lot, Link to comment https://forums.phpfreaks.com/topic/22385-reading-writing-xml-files-to-persistent-storage/#findComment-100354 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.