Skip to main content
Solved

How to create new attributes in XML elements?

  • September 4, 2022
  • 2 replies
  • 130 views

Hi everyone, I have a XML question.

I got an XML structure from filegdb_polygon via GeometryExtractor (GML 3.2.1) and XMLFragmenter:

<gml:Surface gml:id="ID_1" srsName="MysrsName" srsDimension="2"><gml:patches><gml:PolygonPatch><gml:exterior><gml:LinearRing><gml:posList>"list of xy coordinates"</gml:posList></gml:LinearRing></gml:exterior></gml:PolygonPatch></gml:patches>
</gml:Surface>

However, my XML structure should look like this:

<gml:MultiSurface srsName="MysrsName" gml:id="ID_1">
  <gml:surfaceMember>
    <gml:Polygon srsName="MysrsName" gml:id="ID_2">
      <gml:exterior>
        <gml:LinearRing>
          <gml:posList srsDimension="2" count="####">"list of xy coordinates"</gml:posList>
        </gml:LinearRing>
      </gml:exterior>
    </gml:Polygon>
  </gml:surfaceMember>
</gml:MultiSurface>

I used XMLUpdater to delete the attribute

/gml:Surface/@srsDimension

and to rename the following elements (Plain Text) :

//gml:Surface      -> gml:MultiSurface
//gml:patches      -> gml:surfaceMember
//gml:PolygonPatch -> gml:Polygon

But how to create these new attributes:

//gml:Polygon/@srsName
//gml:Polygon/@gml:id
//gml:posList/@srsDimension
//gml:posList/@count

In XMLUpdater documentation it says it can "insert a new element or attribute", but I don't know how to insert new attributes in existing elements.

Best answer by debbiatsafe

Hello @crnila​ 

I checked with our development team, and it is possible to insert attributes using the XMLUpdater.

To insert an attribute using the XMLUpdater, set the Update Type to "Insert as First Child" and the Value Type as "XML/XQuery". For the "Value" parameter, use the following syntax: 

attribute <attrName>{<Value>}

For example, to insert the attribute srsName with a value of MysrsName, use: 

attribute srsName{"MysrsName"} 

Attached is a workspace demonstrating this approach and I hope it helps!

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.

2 replies

debbiatsafe
Safer
Forum|alt.badge.img+21
  • Safer
  • Best Answer
  • September 8, 2022

Hello @crnila​ 

I checked with our development team, and it is possible to insert attributes using the XMLUpdater.

To insert an attribute using the XMLUpdater, set the Update Type to "Insert as First Child" and the Value Type as "XML/XQuery". For the "Value" parameter, use the following syntax: 

attribute <attrName>{<Value>}

For example, to insert the attribute srsName with a value of MysrsName, use: 

attribute srsName{"MysrsName"} 

Attached is a workspace demonstrating this approach and I hope it helps!


  • Author
  • September 9, 2022

Hello @crnila​ 

I checked with our development team, and it is possible to insert attributes using the XMLUpdater.

To insert an attribute using the XMLUpdater, set the Update Type to "Insert as First Child" and the Value Type as "XML/XQuery". For the "Value" parameter, use the following syntax: 

attribute <attrName>{<Value>}

For example, to insert the attribute srsName with a value of MysrsName, use: 

attribute srsName{"MysrsName"} 

Attached is a workspace demonstrating this approach and I hope it helps!

Hi debbiatsafe

Now that you've shown me this, it looks so easy and elegant 😀.

Using the same method, I also inserted the "count" attribute with its value into the "posList" element and everything works perfectly!

Thank you so much!