So I am trying to write to an xml file.

When I do it, NO SYNTAX comes up! BUT, When I go to the xml file it's supposed to write to it looks untouched and none of the data is there.

here is my PHP code:

$xmldoc = new DomDocument( '1.0' );
$xmldoc->preserveWhiteSpace = false;
$xmldoc->formatOutput = true;

$productNum = $_GET["lastm"];
$name = $_GET["docname"];
$category = $_GET["type"];
$content = $_GET["url"];
$user = $_COOKIE["username"];

if( $xml = file_get_contents("http://officedocs.freeserver.me/userdata/" . $user . "/docs.xml") ) {
    $xmldoc->loadXML( $xml, LIBXML_NOBLANKS );

    // find the headercontent tag
    $root = $xmldoc->getElementsByTagName('documents')->item(0);

    // create the <product> tag
    $product = $xmldoc->createElement('document');
    $numAttribute = $xmldoc->createAttribute("lastm");
    $numAttribute->value = $productNum;
    echo "Saving...";

    // add the product tag before the first element in the <headercontent> tag
    $root->insertBefore( $product, $root->firstChild );

    // create other elements and add it to the <product> tag.
    $nameElement = $xmldoc->createElement('name');
    $nameText = $xmldoc->createTextNode($name);

    $categoryElement = $xmldoc->createElement('type');
    $categoryText = $xmldoc->createTextNode($category);

    $urlElement = $xmldoc->createElement('url');
    $urlText = $xmldoc->createTextNode($content);

    $xmldoc->save("http://officedocs.freeserver.me/userdata/" . $user . "/docs.xml");
    echo "All Changes Saved in Office.";


Why won't it write to the xml file?

4 Years
Discussion Span
Last Post by veedeoo
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.