Jump to content

Help with XML Generation


jdadwilson

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.