Skip to main content

Hi.

I haven't really used XML Updater before, but is now tasked with trying to update certain sub-elements i a large hierarchy. I'm trying to update QGIS project files (QGS).

I've extracted the needed replacement tag with content, and routes them in via the "update" connector. But I'm stumped wrt. how it's set up correctly.

My XPath is set to be this: //fieldc@name=fme:get-attribute("fieldname")]/editWidget

This is the location of the tags I want to update (replace) in the source XML file.

But it doesn't replace anything, and it errs with this somewhat cryptic message in the log:

XMLUpdater(XQueryFactory2): The following error occurred while executing query number 1:

XMLUpdater(XQueryFactory2): The following error occurred near line 2, column 26 of the query:

XMLUpdater(XQueryFactory2): invalid expression: syntax error, unexpected "type"

My replacement XML tag looks like this (example):

<editWidget type="TextEdit">
            <config>
              <Option type="Map">
                <Option name="IsMultiline" value="false" type="bool"></Option>
                <Option name="UseHtml" value="false" type="bool"></Option>
              </Option>
            </config>
          </editWidget>

I assume the "type" it's referring to is the type="Map" part of the replacement tag, but it looks like valid XML to me, so what's up with FME (or rather XQueryFactory) ?

Please help.

/Lars

Can you share a sample of the xml you are attempting to update?


Have you tried constructing like this

 //field/@name=@Value(fieldname)]/editWidget

Have you tried constructing like this

 //field/@name=@Value(fieldname)]/editWidget

Yep, fails the same way.


I'm sorry, I can't. For one, it's huge (20K+ lines). And second, it's a regular project file from QGIS, that's easily available. And thirdly, it contains some in-house information, which QGIS insists must be stored in plain text 😞


Further information:

When I use "Delete" instead of "Replace" (as update type), the tag gets deleted as expected.

So it seems that my XPath query works, so the error must be related to the replacement value.

However, that value is generated by an XMLFragmenter transformer, so it should be ok ?


Further information:

When I use "Delete" instead of "Replace" (as update type), the tag gets deleted as expected.

So it seems that my XPath query works, so the error must be related to the replacement value.

However, that value is generated by an XMLFragmenter transformer, so it should be ok ?

I can insert that text into an xml file, which suggests that it's not the problem alone...


I can insert that text into an xml file, which suggests that it's not the problem alone...

I tried to update the XML as plain text, but that just html/xml encoded all "<" and ">" plus some other stuff (into &lt; &gt; etc. resp.).


Well, today it seems to be working.

Lastly I verified that my Xpath worked. I therefore looked at the replacement values, which were created by XMLFragmenter. It seems that the XMLUpdater cannot use these for replacement values as-is for some reason. I'll be making a feature request about this shortly.

I then inserted a StringSearch to extract the XML part, and loose the XML header line. That seems to be working, although I fails to see why this is needed, as the type setting states "XML/XQuery".

Anyhoo, the trick is to strip the replacement value of any XML overhead.


Well, today it seems to be working.

Lastly I verified that my Xpath worked. I therefore looked at the replacement values, which were created by XMLFragmenter. It seems that the XMLUpdater cannot use these for replacement values as-is for some reason. I'll be making a feature request about this shortly.

I then inserted a StringSearch to extract the XML part, and loose the XML header line. That seems to be working, although I fails to see why this is needed, as the type setting states "XML/XQuery".

Anyhoo, the trick is to strip the replacement value of any XML overhead.

I am struggling with the same thing over at https://community.safe.com/s/question/0D5OO000002qX8P0AU/xmlupdater-syntax-error-unexpected-qname

What did you do with the stringsearcher?


I am struggling with the same thing over at https://community.safe.com/s/question/0D5OO000002qX8P0AU/xmlupdater-syntax-error-unexpected-qname

What did you do with the stringsearcher?

Hi Mathiku.

Wow, this was an unexpected stroll down memory lane ;-)

I assume you mean, how did I get rid of the XML header in the replacement value, that blocked the usage in XmlUpdater ?

As fas as I can see and tell (in the ancient 2018 workspace), I used the StringSearcher like this:

billedeI basically just select anything in the proper xml tag (here: <editWidget + anything after it), and saves this into a variable to be used in XmlUpdater.

Hope this helps.

Cheers.


I am struggling with the same thing over at https://community.safe.com/s/question/0D5OO000002qX8P0AU/xmlupdater-syntax-error-unexpected-qname

What did you do with the stringsearcher?

Here's the XmlUpdater:

billede


I am struggling with the same thing over at https://community.safe.com/s/question/0D5OO000002qX8P0AU/xmlupdater-syntax-error-unexpected-qname

What did you do with the stringsearcher?

Thank you. That's similar to what I tried, but I got all these non-revealing errors. But the error might have been caused by something entirely else.


Reply