dkrnl / simplexmlreader Goto Github PK
View Code? Open in Web Editor NEWWrapped XMLReader class, for simple SAX-reading of huge xml.
Wrapped XMLReader class, for simple SAX-reading of huge xml.
$this->registerCallback("/КоммерческаяИнформация/Каталог", array($this, "callbackCatalogEnd"), XMLREADER::END_ELEMENT);
вызывается, но курсор стоит на последнем элементе внутри ожидаемого
$this->registerCallback("/КоммерческаяИнформация/ПакетПредложений", array($this, "callbackOffersListEnd"), XMLREADER::END_ELEMENT);
вообще не вызывается. вот на этом семпле http://pastebin.com/UcWAaPYs
XML reader will fail, if node has not encoded "&" symbol:
<item>
<manufacturer>Villeroy & Boch</manufacturer>
</item>
SimpleXML reader will just silently break on first appearance of incorrect node, and no error will be generated.
If node has &
character string, everything works well.
Is it possible to:
Hi,
first of all, thanks a lot, this is incredibly fast...
i've got simple and probably silly question, i can't figure out how to access an attribute with non default namespace for example xsi:type, of course
$attributes = $elem->attributes();
$ref = $attributes->{"xsi[type]"};
doesn't work...
any idea would be very welcome :)
thabks again for this fantastic work
chris
Hi!
I am trying to implement script. It works blazingly fast for my 16MB file.
My question: how to return correct "name" value for specific language?
My XML
$string = '<?xml version="1.0" encoding="UTF-8"?>
<offer>
<products>
<product>
<description a="b">
<name xml:lang="eng">English translation</name>
<name xml:lang="lat"><![CDATA[HTML code <b>test</b>]]></name>
</description>
</product>
<product>
<description>
<name xml:lang="eng">The same English</name>
<name xml:lang="pol"><![CDATA[HTAnd Polish languagede <b>test</b>]]></name>
</description>
</product>
</products>
</offer>';
I have managed to return correct value of "name" element with xpath and specific language code:
$product['description']['cze'] = $xml->xpath('description/name[@xml:lang = "cze"]');
but this returns array, not string. So I cannot get CDATA code as HTML.
Добрый день.
Не можете - нужно достать данные по каждой группе с учетом вложенности.
/КоммерческаяИнформация/Классификатор/Группы//Группа
Если делать callback по Группа
и expand там - то не понятно, как вытащить информацию о родителе.
<?xml version="1.0" encoding="UTF-8"?>
<КоммерческаяИнформация ВерсияСхемы="2.07" ДатаФормирования="2016-01-12T13:45:00">
<Классификатор СодержитТолькоИзменения="false">
<Ид>798d3ae4-3c2c-4a53-9bc4-589e2db9c7af</Ид>
<ИдКлассификатора>798d3ae4-3c2c-4a53-9bc4-589e2db9c7af</ИдКлассификатора>
<Наименование>Классификатор (Основной каталог товаров)</Наименование>
<Владелец>
<Ид>abf70f82-922a-11df-89ba-001a64b08c02</Ид>
</Владелец>
<Группы>
<Группа>
<Ид>7648d1fb-bbee-11e4-80d3-a0d3c1f1cfaa</Ид>
<Наименование>NEW YEAR 2016</Наименование>
<Группы>
<Группа>
<Ид>f49c9b56-a3fc-11e5-80ea-a0d3c1f1cfaa</Ид>
<Наименование>Новогодний базар</Наименование>
</Группа>
<Группа>
<Ид>b7019a7f-a550-11e5-80ea-a0d3c1f1cfaa</Ид>
<Наименование>Подарок для Него </Наименование>
</Группа>
<Группа>
<Ид>30024644-552d-11e5-80e2-a0d3c1f1cfa9</Ид>
<Наименование>Подарок для Неё</Наименование>
</Группа>
</Группы>
</Группа>
<Группа>
<Ид>9edf9938-facf-11e3-b5c1-001a64b08c00</Ид>
<Наименование>АРОМАТЫ</Наименование>
<Группы>
<Группа>
<Ид>6cfb9f22-0a30-11e5-80dc-a0d3c1f1cfaa</Ид>
<Наименование>Ароматы для дома и свечи</Наименование>
</Группа>
<Группа>
<Ид>9edf9939-facf-11e3-b5c1-001a64b08c00</Ид>
<Наименование>Женские ароматы</Наименование>
</Группа>
</Группы>
</Группа>
</Группы>
</Классификатор>
</КоммерческаяИнформация>
Thank you for this class - it does exactly what I'm looking for - but unfortunately it fails to match some very simple XPath patterns, in particular anything that matches more than a single element. If I test the same patterns in other XPath environments, they work as expected. I note that the docs say that this class matches "simple" XPaths, but doesn't expand on what the limitations are. Here's an example:
Here is an XML file (saved as data.xml
):
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<gmdata>
<header>
<goldmine_version>2017.1.0.377</goldmine_version>
<gmdbdef>
<gmdbfld flddbfname="NOTES" fldname="CREATEDDATE" fldtype="datetime" fldlen="8"></gmdbfld>
<gmdbfld flddbfname="NOTES" fldname="USERID" fldtype="character" fldlen="8"></gmdbfld>
<gmdbfld flddbfname="NOTES" fldname="MODIFIEDDATE" fldtype="datetime" fldlen="8"></gmdbfld>
</gmdbdef>
</header>
</gmdata>
Here is my script:
<?php
require 'vendor/autoload.php';
$reader = new SimpleXMLReader;
$reader->open(__DIR__.'/data.xml');
$gmversion = 'Unknown';
$fielddefs = [];
$reader->registerCallback(
'/gmdata/header/goldmine_version',
function ($reader) use (&$gmversion) {
$element = $reader->expandSimpleXml();
$gmversion = (string)$element;
}
);
$reader->registerCallback(
'/gmdata/header/gmdbdef/gmdbfld',
function ($reader) use (&$fielddefs) {
//gmdbfld elements expected to contain properties:
//flddbfname, fldname, fldtype, fldlen
$element = $reader->expandSimpleXml();
$attrs = $element->attributes();
$fielddef = [];
foreach ($attrs as $name => $value) {
$fielddef[$name] = $value;
}
$fielddefs[$fielddef['flddbfname']][] = [
'table' => $fielddef['flddbfname'],
'name' => $fielddef['fldname'],
'type' => $fielddef['fldtype'],
'length' => $fielddef['fldlen'],
];
}
);
$reader->parse();
$reader->close();
echo 'Goldmine version ', $gmversion;
var_dump($fielddefs);
Only the first of these callbacks triggers - /gmdata/header/goldmine_version
matches a single element and works as expected. The second pattern never matches. Similar patterns like /gmdata/header/gmdbdef
do not match either, yet they do in every other XPath env I've tried them in.
Is this a bug? Or a limitation of using XPath with this class?
Hi,
I tested your code and see that
$this->xml = $reader->expandSimpleXml();
delete some code.
From this:
aaaaaaaaaaa
When I dump it I got in array only: 'CONTACT' => string 'aaaaaaaaaaa' (length=11)
Where are attributes?
No issue here, just saying thank you. I was looking exactly for this, and I was about to write my own version, and I finally found this component, which works very well ! 👍
hi!
I've got a strange issue with the parser. The same PHP function with the same XML file works fine in Windows, but throws an exception in CentOS. The exception is inside expandSimpleXml() and the exact error message is "XMLReader::expand(): /home/mybooklist/xml/-1.xml:1897: parser error : PCDATA invalid Char value 209". Cannot understand this at all, but as a workaround, I want to skip the problem node that causes that error and continue parsing, but it just exits. Here is the code of callback function:
protected function callbackOffer($reader)
{
try {
$element = $reader->expandSimpleXml(); // copy of the current node as a SimpleXMLElement object
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
return true;
}
... parsing $element there
I thought returning true should continue parsing, but it is not. Is it possible to continue parsing after that exception? How?
Thanks!
Сделай плз релиз, чтобы можно было композером устанавливать, если требуемая "minimum-stability": "stable"
вот таким образом обрабатываю xml
class ExampleXmlReader1 extends SimpleXMLReader
{
public function __construct()
{
$this->registerCallback(@iconv('Windows-1251//TRANSLIT//IGNORE','UTF-8', "/realty-feed/offer"), array($this, "callbackOffer"));
// ТИП СДЕЛКИ
$this->registerCallback(@iconv('Windows-1251//TRANSLIT//IGNORE','UTF-8', "/realty-feed/offer/type"), array($this, "callbackType"));
// ВИД НЕДВИЖИМОСТИ
$this->registerCallback(@iconv('Windows-1251//TRANSLIT//IGNORE','UTF-8', "/realty-feed/offer/category"), array($this, "callbackCategory"));
// АДРЕС
//$this->registerCallback(@iconv('Windows-1251//TRANSLIT//IGNORE','UTF-8', "/realty-feed/offer/location/country"), array($this, "callbackREALTY_REGION"));
$this->registerCallback(@iconv('Windows-1251//TRANSLIT//IGNORE','UTF-8', "/realty-feed/offer/location/region"), array($this, "callbackREALTY_REGION"));//область 92
$this->registerCallback(@iconv('Windows-1251//TRANSLIT//IGNORE','UTF-8', "/realty-feed/offer/location/locality-name"), array($this, "callbackREALTY_LOCATION"));//город 94
$this->registerCallback(@iconv('Windows-1251//TRANSLIT//IGNORE','UTF-8', "/realty-feed/offer/location/address"), array($this, "callbackREALTY_STREET"));//улица+дом 95+96
//ОПИСАНИЕ
$this->registerCallback(@iconv('Windows-1251//TRANSLIT//IGNORE','UTF-8', "/realty-feed/offer/description"), array($this, "callbackREALTY_DESCRIPTION"));
//КАРТИНКИ
$this->registerCallback(@iconv('Windows-1251//TRANSLIT//IGNORE','UTF-8', "/realty-feed/offer/image"), array($this, "callbackIMAGES"));
//ПЛОЩАДЬ
$this->registerCallback(@iconv('Windows-1251//TRANSLIT//IGNORE','UTF-8', "/realty-feed/offer/area/value"), array($this, "callbackREALTY_AREA"));
$this->registerCallback(@iconv('Windows-1251//TRANSLIT//IGNORE','UTF-8', "/realty-feed/offer/living-space/value"), array($this, "callbackREALTY_AREA_LIVE"));
//ПАРАМЕТРЫ
$this->registerCallback(@iconv('Windows-1251//TRANSLIT//IGNORE','UTF-8', "/realty-feed/offer/rooms"), array($this, "callbackREALTY_ROOMS"));
$this->registerCallback(@iconv('Windows-1251//TRANSLIT//IGNORE','UTF-8', "/realty-feed/offer/floor"), array($this, "callbackREALTY_FLOOR"));
$this->registerCallback(@iconv('Windows-1251//TRANSLIT//IGNORE','UTF-8', "/realty-feed/offer/floors-total"), array($this, "callbackREALTY_OF_FLOORS"));
//СТОИМОСТЬ
$this->registerCallback(@iconv('Windows-1251//TRANSLIT//IGNORE','UTF-8', "/realty-feed/offer/price/value"), array($this, "callbackREALTY_PRICE"));
//площадь кухни
$this->registerCallback(@iconv('Windows-1251//TRANSLIT//IGNORE','UTF-8', "/realty-feed/offer/kitchen-space/value"), array($this, "callbackREALTY_AREA_KITCHEN"));
}
//OFFER
protected function callbackOffer($reader)
{
global $adsArray;
global $offerArray;
global $adsPropDescription;
$adsArray = array();
$adsPropDescription = array();
$offerArray = array();
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$ref = (string) $attributes->{"internal-id"};
if ($ref) {
$internalID = floatval((string) $xml);
$xpath = $this->currentXpath();
//$adsArray[] = "offer";
$adsArray[] = "$ref";
$offerArray[] = "offer";
$adsPropDescription[] = "151";
}
return true;
}
//ТИП СДЕЛКИ
protected function callbackType($reader)
{
global $adsArray;
global $offerArray;
global $adsPropDescription;
$value = "";
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$value = (string)$xml;
$description = "type";
$xpath = $this->currentXpath();
//echo "</br>".$value;
// echo "1 " . @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$value;\n");
$adsArray[] = @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$value");
$offerArray[] = "";
$adsPropDescription[] = "51";
return true;
}
//ВИД НЕДВИЖИМОСТИ
protected function callbackCategory($reader)
{
global $adsArray;
global $offerArray;
global $adsPropDescription;
$value = "";
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$value = (string)$xml;
$description = "category";
$xpath = $this->currentXpath();
//echo "</br>".$value;
//echo "2 " . @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$description: = $value;\n");
$adsArray[] = @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$value");
$adsPropDescription[] = "56";
$offerArray[] = "";
return true;
}
//REALTY_REGION
protected function callbackREALTY_REGION($reader)
{
global $adsArray;
global $offerArray;
global $adsPropDescription;
$value = "";
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$value = (string)$xml;
$description = "REALTY_REGION";
$xpath = $this->currentXpath();
//echo "</br>".$value;
//echo "3 " . @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$description: = $value;\n");
$adsArray[] = @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$value");
$adsPropDescription[] = "92";
$offerArray[] = "";
return true;
}
//REALTY_LOCATION
protected function callbackREALTY_LOCATION($reader)
{
global $adsArray;
global $offerArray;
global $adsPropDescription;
$value = "";
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$value = (string)$xml;
$description = "REALTY_LOCATION";
$xpath = $this->currentXpath();
//echo "</br>".$value;
//echo "4 " . @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$description: = $value;\n");
$adsArray[] = iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$value");
$adsPropDescription[] = "94";
$offerArray[] = "";
return true;
}
//REALTY_STREET
protected function callbackREALTY_STREET($reader)
{
global $adsArray;
global $offerArray;
global $adsPropDescription;
$value = "";
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$value = (string)$xml;
$description = "REALTY_STREET";
$xpath = $this->currentXpath();
//echo "</br>".$value;
//echo "5 " . @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$value;\n");
$adsArray[] = iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$value");
$adsPropDescription[] = "95";
$offerArray[] = "";
return true;
}
//REALTY_BUILDING
protected function callbackREALTY_BUILDING($reader)
{
global $adsArray;
global $offerArray;
global $adsPropDescription;
$value = "";
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$value = (string)$xml;
$description = "REALTY_BUILDING";
$xpath = $this->currentXpath();
//echo "</br>".$value;
//echo "6 " . @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$description: = $value;\n");
$adsArray[] = iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$value");
$adsPropDescription[] = "96";
$offerArray[] = "";
return true;
}
//REALTY_AREA
protected function callbackREALTY_AREA($reader)
{
global $adsArray;
global $offerArray;
global $adsPropDescription;
$value = "";
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$value = (string)$xml;
$description = "REALTY_AREA";
$xpath = $this->currentXpath();
//echo "</br>".$value;
//echo "7 " . @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$description: = $value;\n");
$adsArray[] = iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$value");
$adsPropDescription[] = "52";
$offerArray[] = "";
return true;
}
//REALTY_AREA_LIVE
protected function callbackREALTY_AREA_LIVE($reader)
{
global $adsArray;
global $offerArray;
global $adsPropDescription;
$value = "";
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$value = (string)$xml;
$description = "REALTY_AREA_LIVE";
$xpath = $this->currentXpath();
//echo "</br>".$value;
//echo "8 " . @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$description: = $value;\n");
$adsArray[] = iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$value");
$adsPropDescription[] = "57";
$offerArray[] = "";
return true;
}
//REALTY_ROOMS
protected function callbackREALTY_ROOMS($reader)
{
global $adsArray;
global $offerArray;
global $adsPropDescription;
$value = "";
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$value = (string)$xml;
$description = "REALTY_ROOMS";
$xpath = $this->currentXpath();
//echo "</br>".$value;
//echo "10 " . @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$description: = $value;\n");
//$adsArray[] = iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$value");
$adsArray[] = $value;
$adsPropDescription[] = "60";
$offerArray[] = "";
return true;
}
//REALTY_FLOOR
protected function callbackREALTY_FLOOR($reader)
{
global $adsArray;
global $offerArray;
global $adsPropDescription;
$value = "";
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$value = (string)$xml;
$description = "REALTY_FLOOR";
$xpath = $this->currentXpath();
//echo "</br>".$value;
//echo "11 " . @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$description: = $value;\n");
//$adsArray[] = iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$value");
$adsArray[] = $value;
$adsPropDescription[] = "63";
$offerArray[] = "";
return true;
}
//REALTY_OF_FLOORS
protected function callbackREALTY_OF_FLOORS($reader)
{
global $adsArray;
global $offerArray;
global $adsPropDescription;
$value = "";
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$value = (string)$xml;
$description = "REALTY_OF_FLOORS";
$xpath = $this->currentXpath();
//echo "</br>".$value;
//echo "12 " . @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$description: = $value;\n");
//$adsArray[] = iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$value");
$adsArray[] = $value;
$adsPropDescription[] = "89";
$offerArray[] = "";
return true;
}
//callbackREALTY_PRICE
protected function callbackREALTY_PRICE($reader)
{
global $adsArray;
global $offerArray;
global $adsPropDescription;
$value = "";
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$value = (string)$xml;
$description = "REALTY_PRICE";
$xpath = $this->currentXpath();
//echo "</br>".$value;
//echo " " . @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$description: = $value;\n");
$adsArray[] = iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$value");
$adsPropDescription[] = "59";
$offerArray[] = "";
return true;
}
//callbackREALTY_DESCRIPTION
protected function callbackREALTY_DESCRIPTION($reader)
{
global $adsArray;
global $offerArray;
global $adsPropDescription;
$value = "";
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$value = (string)$xml;
$description = "REALTY_DESCRIPTION";
$xpath = $this->currentXpath();
//echo "</br>".$value;
//echo " " . @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$description: = $value;\n");
$adsArray[] = iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$value");
$adsPropDescription[] = "detail text";
$offerArray[] = "";
$firstXmlIteration = false;
return true;
}
//IMAGES
protected function callbackIMAGES($reader)
{
global $adsArray;
global $offerArray;
global $adsPropDescription;
$value = "";
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$value = (string)$xml;
$description = "IMAGES";
$xpath = $this->currentXpath();
//echo "</br>".$value;
//echo "13 " . @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$description: = $value;\n");
//$adsArray[] = iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$value");
$adsArray[] = $value;
$adsPropDescription[] = "85";
$offerArray[] = "";
return true;
}
//REALTY_AREA_KITCHEN
protected function callbackREALTY_AREA_KITCHEN($reader)
{
global $adsArray;
global $offerArray;
global $adsPropDescription;
$value = "";
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$value = (string)$xml;
$description = "REALTY_AREA_KITCHEN";
$xpath = $this->currentXpath();
//echo "</br>".$value;
//echo "9 " . @iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$description: = $value;\n");
//$adsArray[] = iconv('UTF-8','Windows-1251//TRANSLIT//IGNORE', "$value");
$adsArray[] = $value;
$adsPropDescription[] = "58";
$offerArray[] = "";
FormRequestForObject($adsArray,$adsPropDescription);
return true;
//FormRequestForObject($adsArray,$adsPropDescription);
}
}
элемент содержит в себе другие элементы со значениями, я сохраняю их в массив, и в конце каждого offer запускаю функцию FormRequestForObject() по сохранению данных с этого массива. Все работает отлично, за исключением того, что когда в xml элементы находятся ниже kitchen-space - они не сохраняются в массив. Это происходит потому, что я вызываю функцию именно на kitchen-space.
Каким образом мне вызывать функцию, чтобы все элементы сохранялись, которые есть в offer. Может быть есть какая то конструкция, которая бы вызывала функцию при закрытии тега /offer
пример загружаемого xml
<?xml version="1.0" encoding="UTF-8"?>
<realty-feed xmlns="http://webmaster.yandex.ru/schemas/feed/realty/2010-06">
<generation-date>2015-07-21T10:10:20+03:00</generation-date>
<offer internal-id="30898">
<type>аренда</type>
<property-type>жилая</property-type>
<url>http://rdgservice.ru/view1.php?c=0&t=0&id=30898</url>
<creation-date>2015-07-21T10:10:20+03:00</creation-date>
<last-update-date>2015-07-21T10:10:20+03:00</last-update-date>
<sales-agent>
<name>Татьяна</name>
<phone>+7(967)1398060</phone>
<category>агентство</category>
<organization>Агентство недвижимости "RDG SERVICE"</organization>
<url>http://rdgservice.ru</url>
</sales-agent>
<price>
<value>40000</value>
<currency>RUR</currency>
<period>месяц</period>
</price>
<description>Сдается 2х комнатная кв. в Новой Трехгорке. Комнаты 16 и 14 кв.м. Кухня 12м. большая ванная комната. Качественный ремонт. Новая мебель. Встроенная техника (посудомоечная и стиральная машина). WiFi интернет и цифровое ТВ. Окна выходят на Подушкинский лесопарк. Подъезд чистый, консьержка. Рядом автобусная остановка и ж.д. станция. Лот № 30898</description>
<area>
<value>68</value>
<unit>кв.м</unit>
</area>
<room-space>
<value>16</value>
<unit>кв.м</unit>
</room-space>
<room-space>
<value>14</value>
<unit>кв.м</unit>
</room-space>
<location>
<country>Россия</country>
<region>Московская обл.</region>
<direction>Минское шоссе</direction>
<distance>6</distance>
<locality-name>Одинцово</locality-name>
<address>Кутузовская,33</address>
</location>
<category>квартира</category>
<rooms>2</rooms>
<rooms-offered>2</rooms-offered>
<room-furniture>1</room-furniture>
<kitchen-furniture>1</kitchen-furniture>
<television>1</television>
<washing-machine>1</washing-machine>
<refrigerator>1</refrigerator>
<balcony>балкон</balcony>
<floor>8</floor>
<floors-total>19</floors-total>
<living-space>
<value>30</value>
<unit>кв.м</unit>
</living-space>
<kitchen-space>
<value>12</value>
<unit>кв.м</unit>
</kitchen-space>
<image>http://rdgservice.ru/bdfiles/flat/30898/55adeccab271e.jpg</image>
<image>http://rdgservice.ru/bdfiles/flat/30898/55adeccb03662.jpg</image>
<image>http://rdgservice.ru/bdfiles/flat/30898/55adeccb48017.jpg</image>
<image>http://rdgservice.ru/bdfiles/flat/30898/55adeccb8aadd.jpg</image>
<image>http://rdgservice.ru/bdfiles/flat/30898/55adeccbcc1c8.jpg</image>
<image>http://rdgservice.ru/bdfiles/flat/30898/55adeccc1d4e3.jpg</image>
<building-type>Панельный</building-type>
<heating-supply>1</heating-supply>
<water-supply>1</water-supply>
<sewerage-supply>1</sewerage-supply>
<electricity-supply>1</electricity-supply>
<gas-supply>1</gas-supply>
<phone>1</phone>
</offer>
</realty-feed>
если kitchen-space опустить вниз, работает отлично, а хотелось бы, чтобы функция сохраняла все элементы при любом их расположении (функция запускалась на закрытии тега offer, или другим способом, но в конце элемента offer)
`
11293
Can i get attribute in view
key_name=>value
Now i can get
foreach ($offer->param as $key=> $item) { echo "name:".$item."<br>"; }
[0]=>XiaoMi
[1]=>4G Smartphone
Can i get
[Brand]=>XiaoMi
[Type]=>4G Smartphone
Делаю парсинг товаров... В поле описания используется CData:
<description><![CDATA[Комфортное и ультрамодное платье в крупную клетку Тиват &ndash; идеальное решение на каждый день для ценительниц всегда актуальной классики в современном исполнении]]></description>
Уже что только не пробовал, но результат получается таков:
["description"]=> object(SimpleXMLElement)#84 (0) { }
Как достать текст в таком случае, подскажите, пожалуйста!
Запустил ваш пример: во первых он не работает в пространстве имен, пришлось все XMLReader заменить на \XMLReader, Exception заменить на \Exception
а вот что это за ошибка вообще не врубаюсь
This is my base code for reading:
$reader = new exampleXmlReader;
$reader->open($file);
$reader->parse();
$reader->close();
But every time the script is started, it will start file parsing from the beginning (obviously).
What I "save" current file position in some log text file, and next time I can "continue" reading from that position?
How this can be implemented?
$reader->registerCallback("by-node-name", function($reader) {
$element = $reader->expandSimpleXml();
$attributes = $element->attributes();
/* ... */
return true;
});
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.