Solved

XMLAppender path issues


Badge

Hi community,

I have some problems using the XMLAppender, to define the correct append path in the main xml document.

The main xml document looks something like this:

<DATA>
  <NAME>Features</NAME>
    <CHILDREN> 
    <Type>
      <NAME>Boulder</NAME>
      <CHILDREN>
        <Type>
          <NAME>Bouldertype1</NAME>
</Type>
  <Type>
          <NAME>Bouldertype2</NAME>
  </Type>
      </CHILDREN>
    </Type> 
    <Type>
      <NAME>Debris</NAME>
      <CHILDREN>
        <Type>
          <NAME>Debris1</NAME>
  </Type>
  <Type>
          <NAME>Debris2</NAME>
  </Type>
      </CHILDREN>
    </Type>
    </CHILDREN>
</DATA> 

The xml_fragments have an attribute that define if they are to be appended to Boulder/Bouldertype1 or Debris/Debris1 etc.. and the xml_fragment's looks something like:

<Type>
 <NAME>Bouldertype1</NAME>
 <item>round</item>
</Type>
<Type>
 <NAME>Debris2</NAME>
 <item>round</item>
</Type>

How do i define the correct path to be used?

icon

Best answer by takashi 18 October 2019, 16:23

View original

10 replies

Badge +16

Have you tried reading the XML document with a XML reader? The reader parameter Elements to match will scan the document and return a path to the selected XML element.

Badge

Have you tried reading the XML document with a XML reader? The reader parameter Elements to match will scan the document and return a path to the selected XML element.

hi @itay, main xml document contain a large number of nested nodes and elements. As you mention it's possible to scan path to elements on the reader setting level but haven't found a similar approach within any other xml transformer. So path for xml fragments to be appended has to be based on attributed variables (correct me if i'm wrong). Haven't found a solution for this yet but not even sure if i'm using the correct approach..

Is it possible to store the path in a fme_xml_element_path format attribute?

I've seen that the xml id is kept, similar to xml_id (encoded: UTF-16LE): "id-Type-1.3.2"

Can this be used in any way? The xml fragments share the same schema but contain one additional children level (4 level) but the main xml document contain only 3 children. So the xml fragment xml_id value or path to second last level (3) would solve my problem.

 

Badge

Have you tried reading the XML document with a XML reader? The reader parameter Elements to match will scan the document and return a path to the selected XML element.

Hi @itay, found out the path can be defined as

 /DATA/CHILDREN/Type{2}/CHILDREN/Type{1}/

the element indexes of 2 and 1 should be able to get from the xml_id

Badge +16

Hi @itay, found out the path can be defined as

 /DATA/CHILDREN/Type{2}/CHILDREN/Type{1}/

the element indexes of 2 and 1 should be able to get from the xml_id

nice one @andre

Badge

nice one @andre

Hi @itay, the path definition might not be the correct approach.. even if i specify other element numbers it still reverts back to the first element in the nested location.. the path values of {} seems to call on existing lists found in the xml reader

Not sure how to continue now..

Userlevel 2
Badge +17

Hi, I would use the XMLUpdater with the following settings, rather than using the XMLAppender.

XMLPath: //Type[data(NAME)=data(fme:get-xml-attribute("xml_fragment")//NAME)]

xmlupdater-example.fmwt (FME 2019.1.3)

0684Q00000ArKzLQAV.png

Result:

<?xml version="1.0" encoding="UTF-8"?><DATA>    <NAME>Features</NAME>    <CHILDREN>        <Type>            <NAME>Boulder</NAME>            <CHILDREN>                <Type>                    <NAME>Bouldertype1</NAME>                    <item>round</item>                </Type>                <Type>                    <NAME>Bouldertype2</NAME>                </Type>            </CHILDREN>        </Type>        <Type>            <NAME>Debris</NAME>            <CHILDREN>                <Type>                    <NAME>Debris1</NAME>                </Type>                <Type>                    <NAME>Debris2</NAME>                    <item>round</item>                </Type>            </CHILDREN>        </Type>    </CHILDREN></DATA>
Badge

Hi, I would use the XMLUpdater with the following settings, rather than using the XMLAppender.

XMLPath: //Type[data(NAME)=data(fme:get-xml-attribute("xml_fragment")//NAME)]

xmlupdater-example.fmwt (FME 2019.1.3)

0684Q00000ArKzLQAV.png

Result:

<?xml version="1.0" encoding="UTF-8"?><DATA>    <NAME>Features</NAME>    <CHILDREN>        <Type>            <NAME>Boulder</NAME>            <CHILDREN>                <Type>                    <NAME>Bouldertype1</NAME>                    <item>round</item>                </Type>                <Type>                    <NAME>Bouldertype2</NAME>                </Type>            </CHILDREN>        </Type>        <Type>            <NAME>Debris</NAME>            <CHILDREN>                <Type>                    <NAME>Debris1</NAME>                </Type>                <Type>                    <NAME>Debris2</NAME>                    <item>round</item>                </Type>            </CHILDREN>        </Type>    </CHILDREN></DATA>

Hi @takashi, thanks for the solution. What if i need to insert the fragments as adjacent siblings or new Childrens? is that also possible by using the XMLUpdater?

Userlevel 2
Badge +17

Hi @takashi, thanks for the solution. What if i need to insert the fragments as adjacent siblings or new Childrens? is that also possible by using the XMLUpdater?

Yes. See the choices in the Update Type column. You can see some Insert methods there.

Badge

Yes. See the choices in the Update Type column. You can see some Insert methods there.

Hi @takashi, that solved it! Nice one, thanks a lot..

Now i hope i can load in 77 different type variables that may contain 1400 fragments

Badge +16

Hi, I would use the XMLUpdater with the following settings, rather than using the XMLAppender.

XMLPath: //Type[data(NAME)=data(fme:get-xml-attribute("xml_fragment")//NAME)]

xmlupdater-example.fmwt (FME 2019.1.3)

0684Q00000ArKzLQAV.png

Result:

<?xml version="1.0" encoding="UTF-8"?><DATA>    <NAME>Features</NAME>    <CHILDREN>        <Type>            <NAME>Boulder</NAME>            <CHILDREN>                <Type>                    <NAME>Bouldertype1</NAME>                    <item>round</item>                </Type>                <Type>                    <NAME>Bouldertype2</NAME>                </Type>            </CHILDREN>        </Type>        <Type>            <NAME>Debris</NAME>            <CHILDREN>                <Type>                    <NAME>Debris1</NAME>                </Type>                <Type>                    <NAME>Debris2</NAME>                    <item>round</item>                </Type>            </CHILDREN>        </Type>    </CHILDREN></DATA>

Hat off to @takashi

Reply