Skip to main content
Solved

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

  • February 14, 2022
  • 3 replies
  • 127 views

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

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

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

3 replies

takashi
Celebrity
  • 7843 replies
  • 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
Celebrity
  • 7843 replies
  • 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
  • 48 replies
  • 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.