Page 1 of 1

XML creation from scratch using DOM/XML (PHP 4.2.x)

Posted: Mon Jul 29, 2002 5:00 pm
by blueser
hi all :)

I've been successfully using DOM/XML native functions to parse XML docs, but I am having a hard time trying to create one from scratch. I've played around with creating the tree elements, but I got stuck with basic things such as specifying non-default encodings or the DOCTYPE entry :?

Anyone been through this? Should I really worry about it?

TIA.

Best,

Andre

Posted: Tue Jul 30, 2002 8:31 am
by volka
if nothing else helps take a look at domxml_open_mem

thks, but...

Posted: Tue Jul 30, 2002 10:04 am
by blueser
Hi volka, thks for the tip. It is not exactly what I need, though, since it assumes there is a well-formed XML string for a start (which is actualy what I am trying to generate ;) ). Like I said earlier, I can generate a bare-bones XML, I just got stuck with customizing it.

However, it did gave me a hint, since domxml_open_mem does processes a string with the <!DOCTYPE ...> DTD definition and a non-default encoding setting on the XML declaration.

So, my probl now is basically to find how <!DOCTYPE ...> and encoding="..." are handled by DOM/XML. I will start by reading a XML with the features I need and start traversing root node's children to see what's in there. Any other clues?

Thks again :)

Best,

Andre

volka was right after all :)

Posted: Tue Jul 30, 2002 12:05 pm
by blueser
I believe I found a suitable workaround, and I was inspired by volka's post.

My attempts to generate a well-formed XML from scratch using DOM/XML all failed. It really looks like some methods are missing, I even listed all methods of the DomDocument class with the get_class_methods function, and none of them helped me.

However, volka's post reminded me I could use domxml_open_mem with an "empty template" (actually, it cannot be totally empty, but this is not a probl) to force DOM to initialize its objects the right way, and then I can proceed from this point adding my own elements to the tree skeleton.

I don't know if this was volka's original suggestion but, so far, it seems to do the job for me (and it's actually easier than doing all by hand ;) )

Thks, volka :)

Best,

Andre