J
J
JohnDaniels2016-04-05 17:43:19
PHP
JohnDaniels, 2016-04-05 17:43:19

What do the @ and # symbols mean when parsing an xml file?

I parse XML using Bitrix tools, I do

$objXML = new CDataXML();
$objXML->LoadString(file_get_contents('upload/importfile.xml'));
$arData = $objXML->GetArray();

in $arData I get a mess
array(1) {
  ["TradeInExport"]=>
  array(2) {
    ["@"]=>
    array(0) {
    }
    ["#"]=>
    array(1) {
      ["Car"]=>
      array(143) {
        [0]=>
        array(2) {
          ["@"]=>
          array(0) {
          }
          ["#"]=>
          array(27) {
            ["InSaleDate"]=>
            array(1) {
              [0]=>
              array(2) {
                ["@"]=>
                array(0) {
                }
                ["#"]=>
                string(10) "11.07.2015"

и т д

Where do they come from?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
Qraxin, 2017-03-23
@JohnDaniels

This is a feature of the GetArray method.
To get rid of them, you need to either collect the array yourself, or rebuild the existing one.
I rebuild like this:

foreach($arXml['feed']['#']['entry'] as $keyEntry => $arValue) {
    foreach($arValue['#'] as $sKey => $sVal) {
        if(is_array($sVal[0]['#']['properties'][0]['#'])) {
            foreach($sVal[0]['#']['properties'][0]['#'] as $keyProp => $valProp){
                $arResult[$keyEntry][$keyProp] = $valProp[0]['#'];
            }
        }
    }
}

Your values ​​of the feed, entry, properties keys may be different or absent.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question