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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
blueser
Forum Newbie
Posts: 3
Joined: Mon Jul 29, 2002 5:00 pm
Location: Rio de Janeiro, Brazil

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

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

if nothing else helps take a look at domxml_open_mem
blueser
Forum Newbie
Posts: 3
Joined: Mon Jul 29, 2002 5:00 pm
Location: Rio de Janeiro, Brazil

thks, but...

Post 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
blueser
Forum Newbie
Posts: 3
Joined: Mon Jul 29, 2002 5:00 pm
Location: Rio de Janeiro, Brazil

volka was right after all :)

Post 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
Post Reply