久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

  1. <legend id='yTfIE'><style id='yTfIE'><dir id='yTfIE'><q id='yTfIE'></q></dir></style></legend>

      <tfoot id='yTfIE'></tfoot>

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

      • <bdo id='yTfIE'></bdo><ul id='yTfIE'></ul>

      如何區(qū)分表示元素和屬性的 SimpleXML 對象?

      How to tell apart SimpleXML objects representing element and attribute?(如何區(qū)分表示元素和屬性的 SimpleXML 對象?)

        <tbody id='VPVz9'></tbody>

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

            <bdo id='VPVz9'></bdo><ul id='VPVz9'></ul>

            <legend id='VPVz9'><style id='VPVz9'><dir id='VPVz9'><q id='VPVz9'></q></dir></style></legend>

          • <tfoot id='VPVz9'></tfoot>

                <i id='VPVz9'><tr id='VPVz9'><dt id='VPVz9'><q id='VPVz9'><span id='VPVz9'><b id='VPVz9'><form id='VPVz9'><ins id='VPVz9'></ins><ul id='VPVz9'></ul><sub id='VPVz9'></sub></form><legend id='VPVz9'></legend><bdo id='VPVz9'><pre id='VPVz9'><center id='VPVz9'></center></pre></bdo></b><th id='VPVz9'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='VPVz9'><tfoot id='VPVz9'></tfoot><dl id='VPVz9'><fieldset id='VPVz9'></fieldset></dl></div>
              1. 本文介紹了如何區(qū)分表示元素和屬性的 SimpleXML 對象?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我需要以特定方式打印任意 SimpleXML 對象,并對屬性節(jié)點進行特殊處理.

                I need to print arbitrary SimpleXML objects in a specific manner, with special handling of attribute nodes.

                問題在于 SimpleXML 元素和屬性似乎使用完全相同的類,屬性節(jié)點甚至假裝支持 attributes() 方法,而 SimpleXML 隱藏了其內(nèi)部結(jié)構(gòu),因此似乎沒有可以通過任何方式告訴節(jié)點類型(除了生成 XML 并重新解析它).

                The problem is that SimpleXML elements and attributes seem to use exactly the same class, attribute node even pretends to support attributes() method, and SimpleXML hides its internals, so there doesn't seem to be any way to tell type of node (short of generating XML and reparsing it).

                兩者都給出相同的結(jié)果:

                $element = new SimpleXMLElement('<foo>test</foo>');
                echo $element;
                print_r($element);
                
                $element = new SimpleXMLElement('<foo attr="test" />');
                echo $element['attr'];
                print_r($element['attr']);
                

                是否有允許在 SimpleXML 中識別節(jié)點類型的隱藏屬性/方法?等效于 DOM 的 $node->nodeType$node instanceof DOMAttr?(我不能用 DOM 代替,支持 SimpleXML 是核心要求).

                Is there a hidden property/method that allows identifying type of node in SimpleXML? Equivalent of DOM's $node->nodeType or $node instanceof DOMAttr? (I can't use DOM instead, support for SimpleXML is core requirement).

                推薦答案

                SimpleXMLElement 中沒有內(nèi)置屬性可以讓您區(qū)分這些.

                There are no built-in properties in SimpleXMLElement which would allow you to tell these apart.

                正如其他人所建議的 dom_import_simplexml 可能是合適的,但是,該功能可以改變有時,節(jié)點是動態(tài)的,例如,如果您傳入子節(jié)點或命名子節(jié)點的列表,它會將它們轉(zhuǎn)換為第一個元素.

                As others have suggested dom_import_simplexml can be appropriate, however, that function can change nodes on the fly sometimes, for example, if you pass in a list of childnodes or named childnodes, it will take those and turn them into the first element.

                如果它是一個空列表,例如沒有從 attributes() 返回的屬性或不存在的命名子節(jié)點,它會給出一個警告,告訴你一個無效的節(jié)點類型已經(jīng)給出:

                If it's an empty list, for example no attributes returned from attributes() or non-existing named childnodes, it will give a warning telling you an invalid nodetype has been given:

                警告:dom_import_simplexml():要導(dǎo)入的節(jié)點類型無效

                Warning: dom_import_simplexml(): Invalid Nodetype to import

                因此,如果您需要使用活潑的布爾值 true/false 進行精確處理,請使用 Simplexml:

                So if you need this precise with a snappy boolean true/false, here is how it works with Simplexml:

                $isElement   = $element->xpath('.') == array($element);
                
                $isAttribute = $element[0] == $element
                               and $element->xpath('.') != array($element);
                

                它與屬性列表和元素列表類似,我只是早上寫了一篇關(guān)于這個的博客,你需要有一些關(guān)于評估什么的具體知識,所以我為它創(chuàng)建了一個備忘單:

                It works similar with attribute lists and element lists, I've just blogged about this in the morning, you need to have some specific knowledge about what to evaluate for what, so I created a cheatsheet for it:

                +------------------+---------------------------------------------+
                | TYPE             | TEST                                        |
                +------------------+---------------------------------------------+
                | Element          | $element->xpath('.') == array($element)     |
                +------------------+---------------------------------------------+
                | Attribute        | $element[0] == $element                     |
                |                  | and $element->xpath('.') != array($element) |
                +------------------+---------------------------------------------+
                | Attributes       | $element->attributes() === NULL             |
                +------------------+---------------------------------------------+
                | Elements         | $element[0] != $element                     |
                |                  | and $element->attributes() !== NULL         |
                +------------------+---------------------------------------------+
                | Single           | $element[0] == $element                     |
                +------------------+---------------------------------------------+
                | Empty List       | $element[0] == NULL                         |
                +------------------+---------------------------------------------+
                | Document Element | $element->xpath('/*') == array($element)    |
                +------------------+---------------------------------------------+
                

                • SimpleXML 類型備忘單(2013 年 2 月 12 日;作者:hakre)
                • 這篇關(guān)于如何區(qū)分表示元素和屬性的 SimpleXML 對象?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                MySQLi prepared statement amp; foreach loop(MySQLi準(zhǔn)備好的語句amp;foreach 循環(huán))
                Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務(wù)器還是從同一用戶獲取記錄?)
                PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數(shù))
                Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結(jié)果填充變量)
                MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“l(fā)ocalhost的訪問被拒絕)

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

                  <tbody id='EisWp'></tbody>
                1. <tfoot id='EisWp'></tfoot>
                    <i id='EisWp'><tr id='EisWp'><dt id='EisWp'><q id='EisWp'><span id='EisWp'><b id='EisWp'><form id='EisWp'><ins id='EisWp'></ins><ul id='EisWp'></ul><sub id='EisWp'></sub></form><legend id='EisWp'></legend><bdo id='EisWp'><pre id='EisWp'><center id='EisWp'></center></pre></bdo></b><th id='EisWp'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='EisWp'><tfoot id='EisWp'></tfoot><dl id='EisWp'><fieldset id='EisWp'></fieldset></dl></div>

                    <legend id='EisWp'><style id='EisWp'><dir id='EisWp'><q id='EisWp'></q></dir></style></legend>
                      <bdo id='EisWp'></bdo><ul id='EisWp'></ul>

                        1. 主站蜘蛛池模板: 成人日韩 | 日日日干干干 | 成人av鲁丝片一区二区小说 | 日韩视频在线免费观看 | 欧美一区二区大片 | 中文精品视频 | 欧美精品中文字幕久久二区 | 久久国产婷婷国产香蕉 | 免费在线观看黄网站 | 亚洲欧美在线视频 | 真人一级毛片 | av网站在线播放 | 国产日韩一区二区三区 | 国产视频二区在线观看 | 亚洲精品一区二区网址 | 国产在线观 | 91文字幕巨乱亚洲香蕉 | 最新伦理片 | 色av一区二区三区 | 视频一二三区 | 久久综合av | 美女黄网站 | 美女久久 | 在线视频久久 | 在线不卡一区 | 在线免费观看毛片 | 成人亚洲精品久久久久软件 | 伊人免费观看视频 | 日本高清aⅴ毛片免费 | 在线免费观看视频你懂的 | 色天堂影院 | 国产剧情一区二区三区 | k8久久久一区二区三区 | 亚洲精品区 | 免费的色网站 | 久久久.com| 欧美日韩亚洲视频 | 久久人| 韩日一区二区 | 欧美一级视频免费看 | 国产精品美女久久久久久免费 |