cobwebch / external_import

Other
20 stars 16 forks source link

Question: Array Path configuration on multiple Nodes #333

Closed bh-teufels closed 4 months ago

bh-teufels commented 4 months ago

how does the arrayPath have to look if the data is under more than one additional node

my data

<emissions>
   <combined>
      <co2>136</co2>
      <co2Class>E</co2Class>
   </combined>
</emissions>
<consumptions>
   <fuel>
      <combined>6</combined>
      <city>7.6</city>
      <suburban>5.8</suburban>
      <rural>5.2</rural>
      <highway>6.1</highway>
   </fuel>
</consumptions>

my configration

'mobilede_xml' => [
        'field' => 'combined',
        'arrayPath' => 'consumptions/fuel/combined',
    ]

but it does not work it get the data from emissions/combined first entry (136)

fsuter commented 4 months ago

Hi. First of all, you need xmlpath for XML structures and not arrayPath. And note that the xpath combines with the field property if it exists (i.e. External Import will first get the node corresponding to the field and then execute the xpath relative to that node). And according to that, the above configuration does not point to an existing XML node.

But then I don't really understand your question. Do you want to import two pieces of information in the same field? Or in two separate fields?

bh-teufels commented 4 months ago

Thank you i want to import the two informations in two seperate fields. so i need to indicate my path with xpath correct? does it work like arrayPath?

so for example to get the consumptions > fuel > combined i have to address it like that:

'mobilede_xml' => [
        'field' => 'consumptions',
        'xpath' => 'fuel/combined',
    ]

and for emissions > combined > co2

'mobilede_xml' => [
        'field' => 'emissions',
        'xpath' => 'combined/co2',
    ]

this seems to working - thank you

fsuter commented 4 months ago

Great!

Can this issue be closed?

bh-teufels commented 4 months ago

yes thank you