jdadwilson Posted August 23, 2007 Share Posted August 23, 2007 I am working on an invoicing application that will store the invoice in xml form in a database. The following function is the start of a more comprehensive structure for the xml. Problem is that it does not work. I am using php 4. I know a little about xml and even less about the DOM. What I have comes from a tutorial on this site. What I want to generate is an xml file as follows <?xml version="1.0"?> <Invoice> <InvInfo> <InvNum>0706001</InvNum> </InvInfo> <Invoice> I want to create the xml string and then create a database record with the string as one field in the record. Because of the structure of the application I must use a function. function GenerateXML() { global $xml_String; $dom = new DOMDocument('1.0'); $xml_Invoice = $dom->appendChild($dom->createElement('Invoice')); $xml_InvInfo = $xml_Invoice->appendChild($dom->createElement('InvInfo')); $xml_InvNum = $xml_InvInfo->appendChild($dom->createElement('InvNum')); $xml_InvNum->appendChild($dom->createTextNode('0706001')); $dom->formatOutput = true; $xml_String = $dom->saveXML(); } TIA for your assistance Quote Link to comment https://forums.phpfreaks.com/topic/66388-help-with-xml-generation/ Share on other sites More sharing options...
XaeroDegreaz Posted August 23, 2007 Share Posted August 23, 2007 Hi. I had the same confusion about XML but it all got cleared up. Check out the SimpleXML stuff for PHP, it's excellent. It treats each tag like an array. No worrying about appendchild and black blah. Then when you want to add something to your document, you can simply callit like an array $xml->$tag["attribute"] = "Hi" And, if it doesn't exist then it creates t for ya Hope this helps. http://kr2.php.net/simplexml Quote Link to comment https://forums.phpfreaks.com/topic/66388-help-with-xml-generation/#findComment-332252 Share on other sites More sharing options...
Barand Posted August 23, 2007 Share Posted August 23, 2007 simplexml requires PHP5 Quote Link to comment https://forums.phpfreaks.com/topic/66388-help-with-xml-generation/#findComment-332273 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.