Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php XML-ID';s用节点id而不是名称替换xml文件中的数据_Php_Html_Xml - Fatal编程技术网

Php XML-ID';s用节点id而不是名称替换xml文件中的数据

Php XML-ID';s用节点id而不是名称替换xml文件中的数据,php,html,xml,Php,Html,Xml,这是我的xml文件的一部分 <entrys> <customer> <name> foo </name> <city> bar </city> </customer> </entrys> 福 酒吧 这就是我要把它改成的 <entrys> <customer> <name id="1"> foo </name>

这是我的xml文件的一部分

<entrys>
   <customer>
    <name> foo </name>
    <city> bar </city>
   </customer>
</entrys>

福
酒吧
这就是我要把它改成的

<entrys>
   <customer>
    <name id="1"> foo </name>
    <city id=”2”> bar </city>
   </customer>
</entrys>

福
酒吧
我的变量反映了第一个示例

<?php

    if (isset($_POST['lsr-submit']))
      {
        header('Location: http://www.domain.net/test.php');
      }

$str = '<?xml version="1.0" encoding="UTF-8"?><entrys></entrys>';
$xml = simplexml_load_string($str);

$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$location = $_POST['location'];
$report = $_POST['report'];
$description = $_POST['desc'];

$fname = htmlentities($fname, ENT_COMPAT, 'UTF-8', false);
$lname = htmlentities($lname, ENT_COMPAT, 'UTF-8', false);
$location = htmlentities($location, ENT_COMPAT, 'UTF-8', false);
$report = htmlentities($report, ENT_COMPAT, 'UTF-8', false);
$description = htmlentities($description, ENT_COMPAT, 'UTF-8', false);

$xml->reports = "";
$xml->reports->addChild('fname', $fname);
$xml->reports->addChild('lname', $lname);
$xml->reports->addChild('location', $location);
$xml->reports->addChild('report', $report);
$xml->reports->addChild('description', $description);

$doc = new DOMDocument('1.0');
$doc->formatOutput = true;
$doc->preserveWhiteSpace = true;
$doc->loadXML($xml->asXML(), LIBXML_NOBLANKS);
$doc->save('test2.xml');

?>
reports=”“;
$xml->reports->addChild($fname',$fname);
$xml->reports->addChild('lname',$lname);
$xml->reports->addChild('location',$location);
$xml->reports->addChild('report',$report);
$xml->reports->addChild('description',$description);
$doc=新DOMDocument('1.0');
$doc->formatOutput=true;
$doc->preserveewhitespace=true;
$doc->loadXML($xml->asXML(),LIBXML\u NOBLANKS);
$doc->save('test2.xml');
?>
这是我表格的一部分

<form name="lsrReports" action="xml/process.php" onSubmit="return defaultagree(this)" method="post" >
<table width="50%" align="center" cellpadding="2" cellspacing="0">
<tr>
<td> name:</td><td> <input type="text" name="name" value=<?php echo $xml->customer->name; ?> /></td>
</tr>
<tr>
<td> city:</td><td> <input type="text" name="city" value=<?php echo $xml->customer->city; ?> /></td>
</tr>
<tr>
<td> state:</td><td> <input type="text" name="state" value=<?php echo $xml->customer->state; ?> /></td>
</tr>
</form>

名称:名称;?>/>
城市:城市;?>/>
状态:状态;?>/>
我的问题是如何通过id而不是使用到目前为止我所写的名称来执行此操作?我希望它是简单的:/

RTFM?例如#10?