PHP Classes

checkout craur

Recommend this page to a friend!

      Generic XML parser class  >  Generic XML parser class package blog  >  Processing XML with a...  >  All threads  >  checkout craur  >  (Un) Subscribe thread alerts  
Subject:checkout craur
Summary:craur is an easy tool for retrieval from xml, json and even csv
Author:Jan Schütze
Date:2012-09-13 11:47:38
Update:2012-09-13 15:20:12

  1. checkout craur   Reply   Report abuse  
Picture of Jan Schütze Jan Schütze - 2012-09-13 15:04:07
I and my company use this (my) little class called craur to work with XML, json and even csv:

Looks like this:

$node = Craur::createFromHtml('<html><head><title>Hans</title></head><body>Paul</body></html>');
assert($node->get('html.head.title') == 'Hans');
assert($node->get('html.body') == 'Paul');

or even collections:

$node = Craur::createFromXml('<book><author>Hans</author><author>Paul</author></book>');
$authors = $node->get('[]');
assert(count($authors) == 2);

If you want you can retrieve also multiple values at once:

$node = Craur::createFromJson('{"book": {"name": "MyBook", "authors": ["Hans", "Paul"]}}');
$values = $node->getValues(
'name' => '',
'book_price' => 'price',
'first_author' => 'book.authors'
'book_price' => 20
assert($values['name'] == 'MyBook');
assert($values['book_price'] == '20');
assert($values['first_author'] == 'Hans');


  2. Re: checkout craur   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2012-09-13 15:20:12 - In reply to message 1 from Jan Schütze
Interesting, seems to be a more straightforward approach than the regular DOMDocument functions.

I think it would be better if you could parse and extract a whole XML document with a single function call as my XML parser class does.