Skip to main content
Solved

XMLAppender path issues


Forum|alt.badge.img

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?

Best answer by takashi

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>
View original
Did this help you find an answer to your question?

10 replies

itay
Supporter
Forum|alt.badge.img+17
  • Supporter
  • October 16, 2019

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.


Forum|alt.badge.img
  • Author
  • October 17, 2019
itay wrote:

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.

 


Forum|alt.badge.img
  • Author
  • October 18, 2019
itay wrote:

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


itay
Supporter
Forum|alt.badge.img+17
  • Supporter
  • October 18, 2019
andre wrote:

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


Forum|alt.badge.img
  • Author
  • October 18, 2019
itay wrote:

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..


takashi
Evangelist
  • Best Answer
  • October 18, 2019

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>

Forum|alt.badge.img
  • Author
  • October 18, 2019
takashi wrote:

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?


takashi
Evangelist
  • October 18, 2019
andre wrote:

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.


Forum|alt.badge.img
  • Author
  • October 18, 2019
takashi wrote:

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


itay
Supporter
Forum|alt.badge.img+17
  • Supporter
  • October 18, 2019
takashi wrote:

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings