<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操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  PHP Upload File Validation(PHP 上传文件验证)
                  PHP Error - Uploading a file(PHP 错误 - 上传文件)
                  How can I write tests for file upload in PHP?(如何在 PHP 中编写文件上传测试?)
                  php resizing image on upload rotates the image when i don#39;t want it to(php在上传时调整图像大小会在我不想要它时旋转图像)
                  How to send additional data using PLupload?(如何使用 PLupload 发送附加数据?)
                  change button text in js/ajax after mp4 =gt;mp3 conversion in php(在 php 中的 mp4 =gt;mp3 转换后更改 js/ajax 中的按钮文本)

                  <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>