<bdo id='ClvTe'></bdo><ul id='ClvTe'></ul>
    <legend id='ClvTe'><style id='ClvTe'><dir id='ClvTe'><q id='ClvTe'></q></dir></style></legend>
  • <small id='ClvTe'></small><noframes id='ClvTe'>

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

      <tfoot id='ClvTe'></tfoot>

      1. PHP中简单而干净的xml操作

        Simple and clean xml manipulation in PHP(PHP中简单而干净的xml操作)
        <i id='87nWM'><tr id='87nWM'><dt id='87nWM'><q id='87nWM'><span id='87nWM'><b id='87nWM'><form id='87nWM'><ins id='87nWM'></ins><ul id='87nWM'></ul><sub id='87nWM'></sub></form><legend id='87nWM'></legend><bdo id='87nWM'><pre id='87nWM'><center id='87nWM'></center></pre></bdo></b><th id='87nWM'></th></span></q></dt></tr></i><div id='87nWM'><tfoot id='87nWM'></tfoot><dl id='87nWM'><fieldset id='87nWM'></fieldset></dl></div>

            • <bdo id='87nWM'></bdo><ul id='87nWM'></ul>

              <small id='87nWM'></small><noframes id='87nWM'>

            • <legend id='87nWM'><style id='87nWM'><dir id='87nWM'><q id='87nWM'></q></dir></style></legend>
            • <tfoot id='87nWM'></tfoot>

                    <tbody id='87nWM'></tbody>

                  本文介绍了PHP中简单而干净的xml操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试寻找一种在 php 中轻松修改 xml 的方法.PHP 文档对于如何轻松操作 xml 非常混乱.我喜欢 SimpleXml 允许轻松查找标签/属性的方式,但它似乎不允许您轻松添加子树或替换现有的.

                  I'm trying to search for a way to easily modify xml in php. The PHP documentation is very confusing regarding how to easily manipulate xml. I like how SimpleXml allows for easily finding tags/attributes, but it doesn't seem to allow you to easily add child trees, or replace existing ones.

                  有什么建议吗?

                  我的用例包括:

                  • 查找具有特定属性的特定标签元素.
                  • 替换找到的元素子树.
                  • 使用从 xml 文本生成的子树.

                  推荐答案

                  我使用 XPATHSimpleXML 来更改我的文件.一个小例子……

                  I use XPATH and SimpleXML to change my file. A little example...

                  xml文件:

                  <?xml version="1.0"?>
                  
                  <forum uri="http://myforum.org/index.php">
                  
                      <item id="1">
                          <title>First Post!!!</title>
                          <link>http://myforum.org/index.php/m/1</link>
                          <description>hello I'm fabio</description>
                      </item>
                  
                      <item id="2">
                          <title>Re: Second post!!!</title>
                          <link>http://myforum.org/index.php/m/2</link>
                          <description>2nd good message.</description>
                      </item>
                  </forum>
                  

                  和 PHP 处理程序:

                  And PHP handler:

                  <?php
                  
                  $forum = simplexml_load_file('forum.xml');
                  
                  /* some xpath EXAMPLES */   
                  /* catch all items in forum */
                  $result = $forum->xpath('/forum/item');
                  /* catch all links */
                  $result = $forum->xpath('//link');
                  /* search for "Re:" in title and returns the item's id */
                  $result = $forum->xpath('//item[contains(title, "Re:")]/@id');
                  /* catch > 10 length items and returns the item's title*/
                  $result = $forum->xpath('//item[string-length(description) > 10]/title');
                  
                  $forum->item[1]->title['url']   = "http://goo.gl/";     /* this add a an attribute */
                  $forum->item[0]->foo            = "newnode";            /* this add content */
                  $forum->item[0]->foo['attrib']  = 10;                   /* this add a another value */
                  $forum->addChild('element_name', 'value');              /* this is a new element /*
                  
                   /* delete value */
                  unset($forum->item[0]);
                  
                  
                  // XML rendering
                  echo $forum->asXML();
                  

                  这篇关于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 的问题)

                  <small id='2md9b'></small><noframes id='2md9b'>

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

                          • <tfoot id='2md9b'></tfoot>