saloonphp / xml-wrangler Goto Github PK
View Code? Open in Web Editor NEW๐ต XML Wrangler - Easily Read & Write XML in PHP
License: MIT License
๐ต XML Wrangler - Easily Read & Write XML in PHP
License: MIT License
Looks like if you have the following XML:
<root>
<nested>
<name>Sam</name>
</nested>
<name>Alex</name>
<name>Taylor</name>
</root>
Then with the following reader code:
$reader->value('nested.name')->get();
Will return:
It would be really cool if you could use the search/reader methods on the base Element
class that comes from the reader.
$reader = XmlReader::fromString(...);
$element = $reader->element('food.2')->sole();
$element->element('name')->sole();
$element->value('name')->sole();
$element->xpathElement('//name')->sole();
$element->xpathValue('//name')->sole();
I've started implementing this as a proof-of-concept.
Not sure if it's related to this library, but I'm trying to parse a Symfony DI Container XML file, and it works fine.
But I cannot parse it using Xpath.
Example:
$example = \Saloon\XmlWrangler\XmlReader::fromString(<<<XML
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true"/>
<service id="kernel" class="TicketSwap\Kernel" public="true" synthetic="true" autoconfigure="true">
<tag name="controller.service_arguments"/>
<tag name="routing.route_loader"/>
</service>
</services>
</container>
XML
);
dump($example->xpathElement('/container/services/service[@id="service_container"]')->get());
// empty array
When I remove xmlns="http://symfony.com/schema/dic/services"
from the <container
root it works.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.