Skip to main content
Solved

How to create new attributes in XML elements?

  • September 4, 2022
  • 2 replies
  • 90 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!

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

2 replies

debbiatsafe
Safer
Forum|alt.badge.img+20
  • 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
debbiatsafe wrote:

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!


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