change1change2 Update xml namespace with data from PHP form-PHP Chinese Network Q&A
Update xml namespace with data from PHP form
P粉445714413
P粉445714413 2023-09-05 10:34:27
0
2
447

In the example below, a PHP form updates the XML with the text entered in the field.

XML 文件 labela.xml:

   change1 change2  

用于更改 XML 文件中的“change1”和“change2”的 PHP 表单

 formatOutput = true; $xml->preserveWhiteSpace = false; $xml->load("labela.xml"); //Get item Element $element = $xml->getElementsByTagName("person")->item(0); //Load child elements $name = $element->getElementsByTagName("name")->item(0); $comment = $element->getElementsByTagName("comment")->item(0); //Replace old elements with new $element->replaceChild($name, $name); $element->replaceChild($comment, $comment); ?> nodeValue = $_POST["namanya"]; $comment->nodeValue = $_POST["commentnya"]; htmlentities($xml->save("labela.xml")); } ?> 
name comment

如何使用 PHP 从下面的 XML 结构中提取并更新字符串change1 和change2?

       change1    change2         change3     

提前感谢所有花时间提供帮助的人

P粉445714413
P粉445714413

reply all (2)
P粉938936304

I think the XML structure needs to be converted into an object

$xmlObject = new SimpleXMLElement($xmlString);

You can then access the property.

    P粉564301782

    Ideally use XPath to extract data from XML. By doing the following you will get the results you want:

    Load.php

    xpath('//pt:data')[0][0] = $change1; $xml->xpath('//pt:data')[1][0] = $change2; $xml->xpath('//pt:data')[2][0] = $change3; $xml->asXML('new_complex_xml.xml');

    Form.php




      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!