<bdo id='2UOlG'></bdo><ul id='2UOlG'></ul>

  1. <small id='2UOlG'></small><noframes id='2UOlG'>

      <legend id='2UOlG'><style id='2UOlG'><dir id='2UOlG'><q id='2UOlG'></q></dir></style></legend>
      <i id='2UOlG'><tr id='2UOlG'><dt id='2UOlG'><q id='2UOlG'><span id='2UOlG'><b id='2UOlG'><form id='2UOlG'><ins id='2UOlG'></ins><ul id='2UOlG'></ul><sub id='2UOlG'></sub></form><legend id='2UOlG'></legend><bdo id='2UOlG'><pre id='2UOlG'><center id='2UOlG'></center></pre></bdo></b><th id='2UOlG'></th></span></q></dt></tr></i><div id='2UOlG'><tfoot id='2UOlG'></tfoot><dl id='2UOlG'><fieldset id='2UOlG'></fieldset></dl></div>
      <tfoot id='2UOlG'></tfoot>

      通过 PHP 在 XML 文件中添加新节点

      adding a new node in XML file via PHP(通过 PHP 在 XML 文件中添加新节点)

        <tbody id='AdKrh'></tbody>
      <legend id='AdKrh'><style id='AdKrh'><dir id='AdKrh'><q id='AdKrh'></q></dir></style></legend>
    1. <small id='AdKrh'></small><noframes id='AdKrh'>

      <tfoot id='AdKrh'></tfoot>

          • <bdo id='AdKrh'></bdo><ul id='AdKrh'></ul>
          • <i id='AdKrh'><tr id='AdKrh'><dt id='AdKrh'><q id='AdKrh'><span id='AdKrh'><b id='AdKrh'><form id='AdKrh'><ins id='AdKrh'></ins><ul id='AdKrh'></ul><sub id='AdKrh'></sub></form><legend id='AdKrh'></legend><bdo id='AdKrh'><pre id='AdKrh'><center id='AdKrh'></center></pre></bdo></b><th id='AdKrh'></th></span></q></dt></tr></i><div id='AdKrh'><tfoot id='AdKrh'></tfoot><dl id='AdKrh'><fieldset id='AdKrh'></fieldset></dl></div>

                本文介绍了通过 PHP 在 XML 文件中添加新节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我只是想问一个问题..如何使用 php 在 xml 中插入新节点.我的 XML 文件 (questions.xml) 在下面给出

                I just wanted to ask a question .. how can i insert a new node in an xml using php. my XML file (questions.xml) is given below

                <?xml version="1.0" encoding="UTF-8"?>
                <Quiz>
                   <topic text="Preparation for Exam">
                      <subtopic text="Science" />
                      <subtopic text="Maths" />
                      <subtopic text="english" />
                   </topic>
                </Quiz>
                

                我想添加一个带有text"属性的新subtopic",即geography".我怎样才能使用 PHP 做到这一点?不过提前谢谢.我的代码是

                I want to add a new "subtopic" with "text" attribute, that is "geography". How can i do this using PHP? Thanks in advance though. well my code is

                <?php
                
                $xmldoc = new DOMDocument();
                $xmldoc->load('questions.xml');
                
                
                
                $root = $xmldoc->firstChild;
                
                $newElement = $xmldoc->createElement('subtopic');
                $root->appendChild($newElement);
                

                //$newText = $xmldoc->createTextNode('geology');//$newElement->appendChild($newText);

                // $newText = $xmldoc->createTextNode('geology'); // $newElement->appendChild($newText);

                $xmldoc->save('questions.xml');
                

                ?>

                推荐答案

                我会使用 SimpleXML 为此.它看起来像这样:

                I'd use SimpleXML for this. It would look somehow like this:

                // Open and parse the XML file
                $xml = simplexml_load_file("questions.xml");
                // Create a child in the first topic node
                $child = $xml->topic[0]->addChild("subtopic");
                // Add the text attribute
                $child->addAttribute("text", "geography");
                

                您可以使用 echo 显示新的 XML 代码,也可以将其存储在文件中.

                You can either display the new XML code with echo or store it in a file.

                // Display the new XML code
                echo $xml->asXML();
                // Store new XML code in questions.xml
                $xml->asXML("questions.xml");
                

                这篇关于通过 PHP 在 XML 文件中添加新节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                • <bdo id='VbCVa'></bdo><ul id='VbCVa'></ul>
                • <i id='VbCVa'><tr id='VbCVa'><dt id='VbCVa'><q id='VbCVa'><span id='VbCVa'><b id='VbCVa'><form id='VbCVa'><ins id='VbCVa'></ins><ul id='VbCVa'></ul><sub id='VbCVa'></sub></form><legend id='VbCVa'></legend><bdo id='VbCVa'><pre id='VbCVa'><center id='VbCVa'></center></pre></bdo></b><th id='VbCVa'></th></span></q></dt></tr></i><div id='VbCVa'><tfoot id='VbCVa'></tfoot><dl id='VbCVa'><fieldset id='VbCVa'></fieldset></dl></div>

                    <tfoot id='VbCVa'></tfoot>

                      <small id='VbCVa'></small><noframes id='VbCVa'>

                            <tbody id='VbCVa'></tbody>
                          <legend id='VbCVa'><style id='VbCVa'><dir id='VbCVa'><q id='VbCVa'></q></dir></style></legend>