FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » building a simple xml object from scratch without dom but with formatting
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
building a simple xml object from scratch without dom but with formatting [message #171727] Wed, 19 January 2011 01:40 Go to previous message
dan is currently offline  dan
Messages: 1
Registered: January 2011
Karma:
Junior Member
Hi All,

I have a tree that i want to generate a printed (string) xml
representation for, and
i would like to determine if it is possible to do it purely with
simple_xml
(SimpleXMLElement), without any reference to dom (DOMDocument).
Further, i would like the tree to print out nicely (indented according
to depth of the leaves in the tree), using only the methods of
SimpleXMLElement.

So, for example, if the tree is
<x>
<y/>
</x>
i would like to do something along the lines of:
$x=new SimpleXMLElement('<x/>');
$x->addChild('y');
$rep=$x->asXML();
echo "$rep\n";

This doesn't work, because i have not added any formatting
information or blank "text nodes" to the simple xml. So i just get
<x><y/></x>
(all on one line) when i print it.

I realize that i could write some code to recursively loop over
the children of the SimpleXMLElement and get the indentation that
way, but i would like to stick to the methods that the
SimpleXMLElement
directly provides.

It seems that this should be possible in principle, because you can
read a formatted tree via code like
$z=simplexml_load_file($file_name);
and when you print it out via code like
$w=$z->asXML();
you get every single space out that you put in.

But how can this be done synthetically (i.e., without
simplexml_load_file()),
and without using anything from dom?

Thanks in advance for any info on this.

dan
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: newbie: Zend or PEAR supported on web hosting company?
Next Topic: Re: hackbar i ajax
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 07:21:02 GMT 2024

Total time taken to generate the page: 0.04069 seconds