highwire/better-dom-document 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

highwire/better-dom-document

最新稳定版本:4.0.1

Composer 安装命令:

composer require highwire/better-dom-document

包简介

BetterDOMDocument is a handy PHP utility class for working with XML. It's a wrapper for PHP's built in DOMDocument that provides a bunch of nice shortcuts that makes working with XML in PHP a breeze. It has great built-in support for namespaces, and xpath.

README 文档

README

Build Status Code Coverage Scrutinizer Code Quality Dependency Status

BetterDOMDocument is a handy PHP utility class for working with XML. It's a wrapper for PHP's built in DOMDocument that provides a bunch of nice shortcuts that makes working with XML in PHP a breeze. It has great built-in support for namespaces, and xpath queries.

composer require highwire/better-dom-document 
<?php use BetterDOMDocument\DOMDoc; // We can load a new BetterDOMDocument from either a string or a DOMNode object $dom = new DOMDoc($xmlstring); // It's easy to output the entire document as an array, which is sometimes easier to work with in PHP $array = $dom->getArray(); // It's easy to query too! $node_list = $dom->xpath('//xpath/to/node', $optional_context_node); // If you know you're only going to find a single DOMNode, you can use a querySingle $dom_node = $dom->xpathSingle('//xpath/to/node'); // Swapping out DOMNodes is really easy $dom->replace($dom_node, $replacementNode); // Removing a node is easy $dom->remove($dom_node); // Most places where you want to pass a DOMNode or element, you can just pass an xpath instead $dom->remove('//xpath/to/element/to/remove'); // The same goes for replacments $dom->replace('//xpath/to/replace', '<xml>You can pass a string, a DOMNode, or a document</xml>'); // It's easy to output the XML $xml = $dom->out(); // Or just output a single DOMNode $xml = $dom->out($dom_node); // Working with namespaced documents is made really easy $xml = '  <entry xmlns="http://www.w3.org/2005/Atom" xmlns:nlm="http://schema.highwire.org/NLM/Journal">  <author>  <name>Li Xu</name>  <nlm:name name-style="eastern">  <nlm:surname>Li</nlm:surname>  <nlm:given-names>Xu</nlm:given-names>  </nlm:name>  </author>  </entry>'; // If your document (like the one above) has a default namespace, you should declare  // it's prefix as the second value when constructing a new BetterDOMDocument $dom = new DOMDoc($xml, 'atom'); // We register the 'atom' prefix against the default namespace // Now we can do mixed namespace queries! $surname = $dom->querySingle('//atom:author/nlm:name/nlm:surname')->nodeValue; // If you need to register another namespace before doing a query, thats a snap. // Note that by default all namespace declarations in the root element are automatically registered.  $dom->registerNamespace('kml','http://www.opengis.net/kml/2.2'); // If you want to query with CSS selectors, no problem! $dom->select('nlm:name[@name-style="eastern"]');

统计信息

  • 总下载量: 25.61k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 15
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 15
  • Watchers: 81
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固