1

I know thins is not secure at all, but it is still before the beta stage and I'm just looking for functionality. So, I have a user input area where they put in their information. From there, the information is sent to a PHP file which makes it an XML file from there. The only problem is, there are no tags so I will show you the code used to create the XML file and the XML file too.

HTML

<form action="insertdata.php" method="post">
        Data1<input name="data" value="" type="text" placeholder="Data">
            Data2 <input name="data2" value="" type="text" placeholder="Data">
            <input type="submit" value="Submit">
        </form>

PHP

  $xml = new DOMDocument("1.0");
$data = $xml ->createElement ("Data");
$datat = $xml -> createTextNode($_POST['data']);
$data = $xml ->appendChild ($datat);

$data1 = $xml -> createElement ("Data1");
$data1t = $xml -> createTextNode ($_POST['data1']);
$data1 = $xml -> appendChild ($data1t);


//echo "<xmp>".$xml -> saveXML (). "</xmp>";
$xml ->save("'".$_POST[data]."'.xml") or die ("error creating file");

So, my problem is not the creation of the XML file, it's that the XML file looks like this:

<?xml version="1.0"?>
Datainput
datainput1

Why isn't the data within the file contained by tags? Also, how would you be able to do this?

4

1 回答 1

1

您创建了元素,但从未使用过它们。和一旦创建就永远不会使用$data$data1因此您所做的只是将两个文本节点附加到根元素。你想要更多类似的东西

$xml = new DOMDocument("1.0");
$data = $xml->createElement('Data'); // Create <Data>
$text = $xml->createTextNode($_POST['data']);  // fill in text node
$data->appendChild($text);  // put textnode inside <Data>...</Data>
$xml->appendChild($data); // insert <Data> into the XML document.
于 2013-06-02T03:21:38.730 回答