Skip to main content
Solved

How to insert XML fragments stored in an attribute into XML document using XMLUpdater

  • February 14, 2022
  • 3 replies
  • 111 views

dms2
Contributor
Forum|alt.badge.img+11
  • Contributor

I have this xml fragment in an attribute called distr_formats and need to insert it in a specified location of an xml document (stored in another attribute):

<gmd:distributionFormat>
    <gmd:MD_Format>
        <gmd:name>
            <gco:CharacterString>DWG</gco:CharacterString>
        </gmd:name>
        <gmd:version>
            <gco:CharacterString>r2013</gco:CharacterString>
        </gmd:version>
        <gmd:fileDecompressionTechnique>
            <gco:CharacterString>ZIP</gco:CharacterString>
        </gmd:fileDecompressionTechnique>
    </gmd:MD_Format>
</gmd:distributionFormat>
<gmd:distributionFormat>
    <gmd:MD_Format>
        <gmd:name>
            <gco:CharacterString>SHP</gco:CharacterString>
        </gmd:name>
        <gmd:version>
            <gco:CharacterString>-</gco:CharacterString>
        </gmd:version>
        <gmd:fileDecompressionTechnique>
            <gco:CharacterString>ZIP</gco:CharacterString>
        </gmd:fileDecompressionTechnique>
    </gmd:MD_Format>
</gmd:distributionFormat>

These are the parameters in my XMLUpdater transformer:

XMLUpdaterI'm getting this error and I'm not sure what I'm doing wrong:

 invalid expression: syntax error, unexpected ">"

Any idea?

Thanks!

Best answer by takashi

Another thought. Just setting this XQuery expression in the Value column could also be possible, instead of transforming the input "distr_formats" string with the method I mentioned above.

This expression returns a sequence consisting of the two <gmd:distributionFormat> elements.

for $x in <temp>@Value(distr_formats)</temp>/*
return $x

 

View original
Did this help you find an answer to your question?

3 replies

takashi
Influencer
  • February 14, 2022

Hi @dms2​ , the reason for the error is that the value of distr_formats is NOT a single XML fragment, it's just a concatenated string of two <gmd:distributionFormat> fragments.

A possible workaround is to transform the value to an XQuery sequence - comma-separated elements quoted by round brackets - before entering it to the XMLUpdater.

(
<gmd:distributionFormat><gmd:MD_Format><gmd:name><gco:CharacterString>DWG</gco:CharacterString></gmd:name><gmd:version><gco:CharacterString>r2013</gco:CharacterString></gmd:version><gmd:fileDecompressionTechnique><gco:CharacterString>ZIP</gco:CharacterString></gmd:fileDecompressionTechnique></gmd:MD_Format>
</gmd:distributionFormat>
,
<gmd:distributionFormat><gmd:MD_Format><gmd:name><gco:CharacterString>SHP</gco:CharacterString></gmd:name><gmd:version><gco:CharacterString>-</gco:CharacterString></gmd:version><gmd:fileDecompressionTechnique><gco:CharacterString>ZIP</gco:CharacterString></gmd:fileDecompressionTechnique></gmd:MD_Format>
</gmd:distributionFormat>
)

How to? For example,

StringReplacer

  • Attributes: distr_formats
  • Mode: Replace Regular Expression
  • Case Sensitive: No
  • Text To Replace: (</gmd:distributionFormat>)\s*(<gmd:distributionFormat>)
  • Replacement Text: \1,\2

StringConcatenator

  •  Expression Results: Overwrite Existing Attributes
  • Attributes To Overwrite: distr_formats
  • Concatenation: (@CurrentAttribute())

 


takashi
Influencer
  • Best Answer
  • February 14, 2022

Another thought. Just setting this XQuery expression in the Value column could also be possible, instead of transforming the input "distr_formats" string with the method I mentioned above.

This expression returns a sequence consisting of the two <gmd:distributionFormat> elements.

for $x in <temp>@Value(distr_formats)</temp>/*
return $x

 


dms2
Contributor
Forum|alt.badge.img+11
  • Author
  • Contributor
  • February 14, 2022

Thank you so much @Takashi Iijima​ .

Both options are good for me but the Xquery expression saves me from adding extra transformers to the flow.

Learning XQuery still is a pending topic I've had for years. I'd like to dig into it some day. I must say though that it's you who I must thank for the little I know of it.


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