DOMXML函数笔记
dom|xml|笔记|函数
/**
* DOMXML函数笔记
* 连接php_domxml.dll后
* 用get_defined_functions()得到domxml支持函数
*
* 目前domxml不支持非iso-8859-1以外的语言声明
* 支持
* 不支持
* 因此需要改造成这样,可能需要
* utf8_encode() utf8_decode() 函数进行处理
*
* 函数列表
* string domxml_version(void) 返回domxml的版本号
* object xmldoc(string str) 从字符串创建XML的Domdocument对象
* object xmldocfile(string filename) 从文件创建XML的Domdocument对象
* object xmltree(string str) 解析xml文档,返回树状结构,不能用domxml函数改变
* resource domxml_add_root(resource doc,string name) 添加根节点
* string domxml_dumpmem(resource doc) 将domxml对象转化为XML串。这个函数有一个问题,他会在第一个汉字前面加一个扩展ascii字符,形如nnn;
* domxml_node_attributes
* domxml_elem_get_attribute
* domxml_elem_set_attribute
* array domxml_node_children(object doc|node) 返回子节点
* domxml_node_new_child
* object domxml_node(string name) 创建一个节点节点
* domxml_node_unlink_node
* int domxml_node_set_content(resource doc,string content) 设置节点内容
* object domxml_new_xmldoc(string version) 创建新的空XML对象
* xpath_new_context
* xpath_eval
* xpath_eval_expression
* xptr_new_context
* xptr_eval
* object domxml_root(object doc) 返回根节点
* array domxml_attributes(resource note) 获取节点属性
* object domxml_get_attribute(resource doc,string name) 读取属性
* domxml_getattr
* object domxml_set_attribute(resource doc,string name,string value) 添加属性
* domxml_setattr
* array domxml_children(object doc|node) 返回子节点
* resource domxml_new_child(string name,string content) 添加子节点
* domxml_unlink_node
* set_content
* new_xmldoc
*
*/
?>
<br><?php <br/>// 文档 xml源树.xml 内容<br>$testxml = '<br><?xml version="1.0" encoding="GB2312"?> <br><root><br><note>读取xml文档时,处理器将形成一个树,我们将其叫做源树。该树具有表中的各种类型的节点。<br></note><br><title>源树具有的节点</title> <br><table> <br><tr> <th>节点类型</th> <th>说明</th> </tr> <br><tr> <td>Root(根)</td> <td>这是树的根节点。可以出现在树的任何地方。根节点只具有一个子节点,子节点指的是xml文档中的文档元素节点。</td> </tr> <br><tr> <td>Element(元素)</td> <td>这种节点用于文档中的任何元素。元素节点的子节点可以是其内容的元素节点、注释节点、处理信息节点以及文本节点。</td> </tr> <br><tr> <td>Text(文本)</td> <td>文档中出现的所有文本,都分组归入到文本节点中。文本节点不可以有同为文本节点的紧接着的前或后的兄弟节点。</td> </tr> <br><tr> <td>Attribute(属性)</td> <td>每一个元素节点都有一套自己附加的属性节点。默认的属性值以与指定属性一样的方法来处理。这些节点都没有子节点。</td> </tr> <br><tr> <td>Namespace(名称)</td> <td>对于每一个以xlmns:和属性节点开头的元素,都有一个名称空格节点。这些节点没有子节点。</td> </tr> <br><tr> <td>Processing Instruction(处理指令)</td> <td>每一个处理指令都有一个单独的节点。这些节点都没有子节点。</td> </tr> <br><tr> <td>Comment(注释)</td> <td>每一个都有一个注释节点。这些节点都没有子节点。</td> </tr> <br> </table> <br></root><br>';<br><br>echo "domxml版本:".domxml_version();<br>echo "<p> </p>";<br>// xmltree domxml_dumpmem<br>$filename = "xml源树.xml";<br>//$filename = "resume.xml";<br>$fp = fopen($filename,"r"); <br>$inXML = fread($fp,filesize($filename)); <br>fclose($fp); <br>// 删除语言设定<br>//$inXML = str_replace(' encoding="GB2312"',"",$inXML);<br>$inXML = eregi_replace(' encoding="[a-z0-9_-]+"',"",$inXML);<br><br>$doc = xmltree($inXML); // 使用xmltree解析<br>$myxml = $doc->dumpmem(); // 转换成字串,头为 xml version="1.0"<br> // 如果再执行一次,头将变成 xml version="1.0" encoding="ISO-8859-1"<br>//$myxml = eregi_replace('[0-9]+;',"",$myxml); // 删除<br>echo "用xmltree解析<br>";<br>echo "<textarea cols="60" rows="5">$myxml</textarea><br>";<br>//print_r($doc); // 可以看到整个树 亦可用var_dump($doc);<br><br>// xmldoc<br>$doc = xmldoc($inXML); <br>$myxml = $doc->dumpmem();<br>echo "用xmldoc解析<br>";<br>echo "<textarea cols="60" rows="5">$myxml</textarea><br>";<br>//print_r($doc); // 只能看到根节点<br><br>// domxml_new_xmldoc<br>$doc = domxml_new_xmldoc("1.0");<br><br>$root = $doc->add_root("HTML");<br>$head = $root->new_child("HEAD", "");<br>$head->new_child("TITLE", "DOMXML 测试0");<br>$head->new_child("TITLE", "DOMXML 测试1");<br>$head->set_attribute("Language", "ge");<br>domxml_node_set_content($head,"ppp"); // 设置节点的内容,多次执行是叠加的<br>domxml_node_set_content($head,"ttt");<br><br>// 是乎函数名中只有1-2个"_"的函数,可作为对象的方法使用<br><br>$myxml = $doc->dumpmem();<br>echo "自定义xml<br>";<br>echo "<textarea cols="60" rows="5">$myxml</textarea><br>";<br><br>// 节点的遍历<br>/**<br> 节点结构<br> DomElement Object<br> type = 1<br> tagname = 节点名<br> DomText Object<br> type = 3<br> content = 节内容点<br> DomCData Object<br> type = 4<br> content = 节内容点<br><br> DomProcessingInstruction Object<br> type 无<br> target = 处理指令<br> data = 参数<br> <br>*/<br>$ar[] = $doc->root(); // 取得根节点<br>$ar[] = $ar[count($ar)-1]->children();<br>$ar[] = $ar[count($ar)-1][0]->children();<br><br>// 函数domxml_children() 不能返回节点参数<br>// 返回节点参数需要使用domxml_attributes()<br>//var_dump(domxml_attributes($head));<br>//print_r($ar[1][0]->attributes());<br>//print_r($ar);<br><br>function xml_dumpmem($xmldoc) {<br> static $mode = 0;<br> $xmlstr = "";<br> // 获取节点,保存在数组中<br> if(get_class($xmldoc) == "DomDocument") {<br> $xmlstr = '<?xml version="1.0" encoding="gb2312"?>'."\n";<br> if(count($xmldoc->children) == 1) // 根节点,没有其他成员<br> $docs[] = $xmldoc->root();<br> else<br> $docs = $xmldoc->children(); // 根节点,有其他成员<br> }else {<br> $docs = $xmldoc->children(); // 一般节点<br> }<br> <br>// echo __LINE__."<br>";<br> foreach($docs as $doc) {<br> $attr = $doc->attributes();<br> switch($doc->type) {<br> case 1:<br> $xmlstr .= "tagname}"; // 标签头<br> if($attr) {<br> foreach($attr as $key)<br> $xmlstr .= " {$key->name}=\"{$key->value}\""; // 标签参数<br> }<br> $xmlstr .= ">"; // 标签结束<br> $xmlstr .= xml_dumpmem($doc); // 进入子节点<br> $xmlstr .= "{$doc->tagname}>"; // 闭合标签<br> break;<br> case 3:<br> $xmlstr .= $doc->content;<br> break;<br> case 4:<br> $xmlstr .= " $xmlstr .= $doc->content;<br> $xmlstr .= "]]>";<br> break;<br> default:<br> if(get_class($doc) == "DomProcessingInstruction") {<br> $xmlstr .= "{$doc->target}";<br> $xmlstr .= " {$doc->data}?>\n";<br> }<br> break;<br> }<br> }<br> return $xmlstr;<br>}<br><br>if(1) {<br> $filename = "resume.xml";<br>// $filename = "resume.xsl";<br> $filename = "xml源树.xml";<br> $fp = fopen($filename,"r"); <br> $inXML = fread($fp,filesize($filename)); <br> fclose($fp); <br> $inXML = eregi_replace(' encoding="[a-z0-9_-]+"',"",$inXML);<br>// $doc = xmltree($inXML); // 使用xmltree解析<br> $doc = xmldoc($inXML); // 使用xmldoc解析<br>}<br><br>// 不能用来解析xsl文档<br><br>$myxml = xml_dumpmem($doc);<br>echo "自己写一个dumpmem就不出错了<br>";<br>echo "<textarea cols="60" rows="5">$myxml</textarea><br>";<br>print_r($doc);<br><br>?><br>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

By default, the title bar color on Windows 11 depends on the dark/light theme you choose. However, you can change it to any color you want. In this guide, we'll discuss step-by-step instructions for three ways to change it and personalize your desktop experience to make it visually appealing. Is it possible to change the title bar color of active and inactive windows? Yes, you can change the title bar color of active windows using the Settings app, or you can change the title bar color of inactive windows using Registry Editor. To learn these steps, go to the next section. How to change title bar color in Windows 11? 1. Using the Settings app press + to open the settings window. WindowsI go to "Personalization" and then

Do you see "A problem occurred" along with the "OOBELANGUAGE" statement on the Windows Installer page? The installation of Windows sometimes stops due to such errors. OOBE means out-of-the-box experience. As the error message indicates, this is an issue related to OOBE language selection. There is nothing to worry about, you can solve this problem with nifty registry editing from the OOBE screen itself. Quick Fix – 1. Click the “Retry” button at the bottom of the OOBE app. This will continue the process without further hiccups. 2. Use the power button to force shut down the system. After the system restarts, OOBE should continue. 3. Disconnect the system from the Internet. Complete all aspects of OOBE in offline mode

Taskbar thumbnails can be fun, but they can also be distracting or annoying. Considering how often you hover over this area, you may have inadvertently closed important windows a few times. Another disadvantage is that it uses more system resources, so if you've been looking for a way to be more resource efficient, we'll show you how to disable it. However, if your hardware specs can handle it and you like the preview, you can enable it. How to enable taskbar thumbnail preview in Windows 11? 1. Using the Settings app tap the key and click Settings. Windows click System and select About. Click Advanced system settings. Navigate to the Advanced tab and select Settings under Performance. Select "Visual Effects"

We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety
