Skip to main content

I am trying to update a single value within an attribute containing XML using the value from another attribute. Below i am trying to update the value within LOV_TYPE to be "Corp Yard" (which is coming from an existing attribute. This is a snippet from the XML of which there are dozens of CUSTOMFIELD entities that are defined by the PROPERTYCODE.

I am totally new to XQuery and am using the XMLXQueryUpdater with the below settings:

XQuery Input: XQuery Expression

XQuery Expression:

for $node in attribute {fme:get-attribute("XML")}//CUSTOMFIELD where $node/PROPERTYCODE = "OWN-ORG" return (replace value of node $node/LOVSETTINGS/LOV_TYPE with {fme:get-attribute("New_Own_Org")},)

XML Input; Attribute specifying XML

XML Attribute: XML

 

Any help would be much appreciated.

 

<ns23:CUSTOMFIELD index="30" entity="OBJ" type="RENT">

<ns23:PROPERTYCODE>OWN-ORG</ns23:PROPERTYCODE>

<ns23:PROPERTYLABEL>Owning Organization</ns23:PROPERTYLABEL>

<ns23:CLASSID>

<ns23:CLASSCODE>*</ns23:CLASSCODE>

<ns23:ORGANIZATIONID>

<ns23:ORGANIZATIONCODE>*</ns23:ORGANIZATIONCODE>

</ns23:ORGANIZATIONID>

</ns23:CLASSID>

<ns23:ENTITYCODEFIELD entity="QUAL">

<ns23:CODEVALUE/>

</ns23:ENTITYCODEFIELD>

<ns23:LOVSETTINGS>

<ns23:LOV_TYPE>Engineering</ns23:LOV_TYPE>

<ns23:LOV_VALIDATE>+</ns23:LOV_VALIDATE>

</ns23:LOVSETTINGS>

</ns23:CUSTOMFIELD>

 

I updated the XQuery to the below and it is no longer throwing an invalid XQuery error. But it is still not updating the value for LOV_TYPE.

for $node in /*/*/*/*/*/*:USERDEFINEDAREA/*:CUSTOMFIELD where $node/PROPERTYCODE = "OWN-ORG"

return (replace value of node $node/LOVSETTINGS/LOV_TYPE with {fme:get-attribute("New_Own_Org")})


Hi @lopes8, I think you are using XMLXQueyrUpdater, not XMLUpdater. The title of this question misleads us...

You cannot omit namespace prefix for any level of elements, in XQuery expressions, but you can use the wildcard * if necessary.

Try this expression.

for $node in //*:CUSTOMFIELD
where $node/*:PROPERTYCODE = "OWN-ORG"
return (
    replace value of node $node/*:LOVSETTINGS/*:LOV_TYPE
    with {fme:get-attribute("New_Own_Org")}
)

 

Alternatively, if you know the full namespace URI of "ns23", you can declare it as the default namespace and omit the namespace prefix in the expression, as in:

declare default element namespace "<replace this with the correct namespace URI>";
for $node in //CUSTOMFIELD
where $node/PROPERTYCODE = "OWN-ORG"
return (
    replace value of node $node/LOVSETTINGS/LOV_TYPE
    with {fme:get-attribute("New_Own_Org")}
)

Hi @lopes8, I think you are using XMLXQueyrUpdater, not XMLUpdater. The title of this question misleads us...

You cannot omit namespace prefix for any level of elements, in XQuery expressions, but you can use the wildcard * if necessary.

Try this expression.

for $node in //*:CUSTOMFIELD
where $node/*:PROPERTYCODE = "OWN-ORG"
return (
    replace value of node $node/*:LOVSETTINGS/*:LOV_TYPE
    with {fme:get-attribute("New_Own_Org")}
)

 

Alternatively, if you know the full namespace URI of "ns23", you can declare it as the default namespace and omit the namespace prefix in the expression, as in:

declare default element namespace "<replace this with the correct namespace URI>";
for $node in //CUSTOMFIELD
where $node/PROPERTYCODE = "OWN-ORG"
return (
    replace value of node $node/LOVSETTINGS/LOV_TYPE
    with {fme:get-attribute("New_Own_Org")}
)

Thank you @takashi for your response.  You are correct, I apologize for referencing the incorrect  XMLUpdater transformer instead of the XMLXQueryUpdater.  I have updated the post and tags to reflect the correct transformer.

 

The expression you provided is working exactly as needed.  Thank you

Reply