Code Monkey home page Code Monkey logo

xml-wrangler's Issues

Error multiple queries

I try run and works fine
$el = $xmlReader->value('infNFe.det.2')->sole();
Result

image

But a try multiple queries and give error

$el = $xmlReader->value('infNFe.det.2.prod')->sole();

image

Bug: Dot-notation not working as expected for nested values

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:

  • Sam
  • Alex
  • Taylor

Xpath doesn't work when `xmlns` is used

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.

Add the ability to chain reader methods on `Element` class

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.