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:

<?php
$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;
    $product->appendChild($numAttribute);
    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');
    $product->appendChild($nameElement);
    $nameText = $xmldoc->createTextNode($name);
    $nameElement->appendChild($nameText);

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

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

    $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?

does your webserver has writing permision on that xml?

so what should I do?

are you asking how to check for file permisions?
that depens on your server (windows/linux/..)

Can we see the docs.xml you are trying to add the new entries?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.