PHPackages                             niji/xml-parser-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. niji/xml-parser-bundle

ActiveSymfony-bundle[Parsing &amp; Serialization](/categories/parsing)

niji/xml-parser-bundle
======================

Symfony bundle that allows easy parsing of XML documents using a YAML mapping file and XPath.

1.1(7y ago)1209MITPHPPHP ^7.0

Since Nov 26Pushed 6y ago4 watchersCompare

[ Source](https://github.com/NijiDigital/xml_parser_bundle)[ Packagist](https://packagist.org/packages/niji/xml-parser-bundle)[ RSS](/packages/niji-xml-parser-bundle/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (7)Versions (5)Used By (0)

XML Parser Bundle
=================

[](#xml-parser-bundle)

This bundle allows easy parsing using XPath.

Installation
------------

[](#installation)

`composer req niji/xml-parser-bundle`

XPath parsing
-------------

[](#xpath-parsing)

To parse an XPath file, you need to:

1. Create a parameter YAML file like this:

```
parameters:
  xml_parsers.mappings:
    mapping_a:
      destination_class: 'App\Entity\EntityName'
      base_root: '//namespace:XMLNode/XMLSubNode'
      mapping:
        property_dest: 'source_property_name'
        property_dest2: 'source_property2_name'
        sub_entity:
          destination_class: 'App\Entity\SubEntityName'
          base_root: 'XMLNodeName'
          mapping:
            sub_entity_property: 'source_subentity_property'
            ...
        ...
```

If your XML have `""` as default namespace, use `default` as namespace name for your XPath queries.

The `destination_class` key is optional, if no destination class is specified the parser will return an associative `array` as result.

2. Add the `Niji\XmlParserBundle\XmlParsingTrait` to your destination class:

```
