Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Form Submission to xml

Options
  • 09-01-2007 10:23pm
    #1
    Closed Accounts Posts: 493 ✭✭


    Hi,

    Im new to the whole php creation. However, i have created a site which reads information from an xml file and shows it on screen.

    I now want to create a page which allows the user to fill in a form (headline and body for example) and when they choose submit it gets written to the xml file.

    Any ideas on a simple structure?


Comments

  • Registered Users Posts: 568 ✭✭✭phil


    It does really depend I guess whether this information needs to conform to a DOM, but in general writing XML is much easier than reading it.

    PHP uses a SAX based parser for reading/writing XML, but you can simply use good ol' print to write it :) (the third option is to use the DOM)

    First of all I guess is to tell us whether you're using a procedural style of PHP or OO (OO - class based ; procedural - linear function based)

    Second is the version of PHP you're using, PHP 4.x or PHP 5.x (or God forbid PHP 3.x)

    Writing XML can be done with good 'ol print i.e.
    $xml_write =<<<EOXML;
    <?xml version='1.0' encoding='utf-8'?>
    <car>
       <make> BMW </make>
       <model> 318 </model>
       <engine> 1.8 </engine>
    </car>
    EOXML;
    


    The $xml_write variable can now be written to screen or to a file to output an XML "file".

    e.g.
    $fp = fopen("test.xml", "w")
    fputs($fp, $xml_write);
    fclose($fp);
    

    I'm not 100% that the code is syntactically correct, treat it as pseudo-code until you test it yourself :)

    We can be more specific if you tell me the information above.

    Phil.


Advertisement