removing parent nodes based on child node attribute or value

Having trouble installing Oxygen? Got a bug to report? Post it all here.
upperhouse
Posts: 1
Joined: Wed Jan 18, 2023 11:04 pm

removing parent nodes based on child node attribute or value

Post by upperhouse »

Hello, newbie question here.
I have multiple nodes with this structure:

Code: Select all

<Placemark>
    <name>State House District 22</name>
    <Style>
    <LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle>
    </Style>
    <ExtendedData>
        <SchemaData schemaUrl="#State_Legislative_Districts_Lower_Houses">
            <SimpleData name="OBJECTID">1</SimpleData>
            <SimpleData name="AREALAND">297416805</SimpleData>
            <SimpleData name="AREAWATER">1125626</SimpleData>
            <SimpleData name="BASENAME">22</SimpleData>
            <SimpleData name="CENTLAT">+47.6078421</SimpleData>
            <SimpleData name="CENTLON">-111.4695096</SimpleData>
            <SimpleData name="FUNCSTAT">N</SimpleData>
            <SimpleData name="GEOID">30022</SimpleData>
            <SimpleData name="INTPTLAT">+47.6063469</SimpleData>
            <SimpleData name="INTPTLON">-111.4675708</SimpleData>
            <SimpleData name="LDTYP">O</SimpleData>
            <SimpleData name="LSADC">LL</SimpleData>
            <SimpleData name="LSY">2022</SimpleData>
            <SimpleData name="MTFCC">G5220</SimpleData>
            <SimpleData name="OID">2.13903180861662e+15</SimpleData>
            <SimpleData name="SLDL">022</SimpleData>
            <SimpleData name="STATE">30</SimpleData>
            <SimpleData name="SHAPE_Length">1.07988045909769</SimpleData>
            <SimpleData name="SHAPE_Area">0.0357120795919999</SimpleData>
        </SchemaData>
    </ExtendedData>
    <MultiGeometry>
        <Polygon>
            <outerBoundaryIs>
                <LinearRing>
                    <coordinates></coordinates>
                </LinearRing>
            </outerBoundaryIs>
        </Polygon>
    </MultiGeometry>
</Placemark>
<Placemark>
Trying to remove all other similar Placemanrk nodes that don't have that SimpleData child node (with STATE attribute), that has a value of "30".
Tried this with the refactor tool (delete element), but it comes back with "No resources were affected":
Placemark[not(ExtendedData/SchemaData/SimpleData/text() = '30')]

Any advice is appreciated.
Thank you!
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: removing parent nodes based on child node attribute or value

Post by Radu »

Hi,

I'm afraid I do not understand what you want to remove, your sample only includes one Placemark, do you want to remove that or other Placemark elements which adhere to a certain criteria.
Let's assume you have an XML document like this:

Code: Select all

<root>
	<Placemark>
 ...
   ....
    <ExtendedData>
        <SchemaData schemaUrl="#State_Legislative_Districts_Lower_Houses">
            ....
            <SimpleData name="STATE">30</SimpleData>
...
        </SchemaData>
    </ExtendedData>
  ....
      </Placemark>
	<Placemark>
    ....
    <ExtendedData>...
            <SimpleData name="STATE">31</SimpleData>
...
        </SchemaData>
    </ExtendedData>
</Placemark>
</root>
So two placemark elements, one has SimpleData=30, the other SimpleData=31.
In the Oxygen "XPath" toolbar you can try an xpath like yours:

Code: Select all

//Placemark[not(ExtendedData/SchemaData/SimpleData/text() = '30')]
It should select the second "Placemark". Is this that you want?
Also if your root element has a namespace declaration on it, the XPath should take the namespace into account like:

Code: Select all

//*:Placemark[not(*:ExtendedData/*:SchemaData/*:SimpleData/text() = '30')]

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply