Remove KML elements that do not contain certain values
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 1
- Joined: Sun May 12, 2019 5:44 am
Remove KML elements that do not contain certain values
Post by billswerski »
Hello,
I have a large KML file that follows this format:
I want to be able to remove all <Placemark> elements and child elements that do not match either
<Placemark>
<name>POTOMAC RIVER</name>
or
<Placemark>
<ExtendedData>
<SchemaData schemaUrl="#OGRGeoJSON">
<SimpleData name="DIG_NAME">POTOMAC RIVER</SimpleData>
I've tried a lot of XSLT and XML Refactoring methods, and while this seems like it should be easy, I can't figure it out. Any help would be appreciated!
I have a large KML file that follows this format:
Code: Select all
<Document id="root_doc">
<name>Perennial_Streams.kml</name>
<Schema name="OGRGeoJSON" id="OGRGeoJSON">
<SimpleField type="int" name="OBJECTID"></SimpleField>
<SimpleField type="int" name="HYDROID"></SimpleField>
<SimpleField type="string" name="FTYPE"></SimpleField>
<SimpleField type="int" name="FCODE"></SimpleField>
<SimpleField type="string" name="DIG_NAME"></SimpleField>
<SimpleField type="string" name="DRAIN"></SimpleField>
<SimpleField type="int" name="RCHID"></SimpleField>
<SimpleField type="string" name="VISIBLE"></SimpleField>
<SimpleField type="string" name="SOURCE"></SimpleField>
</Schema>
<StyleMap id="m_ylw-pushpin">
<Pair>
<key>normal</key>
<styleUrl>#s_ylw-pushpin</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#s_ylw-pushpin_hl</styleUrl>
</Pair>
</StyleMap>
<Style id="s_ylw-pushpin_hl">
<IconStyle>
<scale>1.3</scale>
<Icon>
<href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
</Icon>
<hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
</IconStyle>
<LineStyle>
<color>ffffa35c</color>
<width>3.7</width>
</LineStyle>
<PolyStyle>
<color>ffffaa55</color>
</PolyStyle>
</Style>
<Style id="s_ylw-pushpin">
<IconStyle>
<scale>1.1</scale>
<Icon>
<href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
</Icon>
<hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
</IconStyle>
<LineStyle>
<color>ffffa35c</color>
<width>3.7</width>
</LineStyle>
<PolyStyle>
<color>ffffaa55</color>
</PolyStyle>
</Style>
<Folder>
<name>OGRGeoJSON</name>
<Placemark>
<name>POTOMAC RIVER</name>
<styleUrl>#m_ylw-pushpin</styleUrl>
<ExtendedData>
<SchemaData schemaUrl="#OGRGeoJSON">
<SimpleData name="OBJECTID">2042</SimpleData>
<SimpleData name="HYDROID">100006243</SimpleData>
<SimpleData name="FTYPE">RIVER</SimpleData>
<SimpleData name="FCODE">46010</SimpleData>
<SimpleData name="DIG_NAME">POTOMAC RIVER</SimpleData>
<SimpleData name="DRAIN"></SimpleData>
<SimpleData name="RCHID">0</SimpleData>
<SimpleData name="VISIBLE">Y</SimpleData>
<SimpleData name="SOURCE">RPA Field</SimpleData>
</SchemaData>
</ExtendedData>
<LineString>
<extrude>1</extrude>
<altitudeMode>relativeToGround</altitudeMode>
<coordinates>
-77.2485765431118,38.992016208902,30 ... -77.24745515099529,38.9883802722356,30
</coordinates>
</LineString>
</Placemark>
<Placemark>
...
</Placemark>
<Placemark>
...
</Placemark>
<Placemark>
...
</Placemark>
<Placemark>
<name>POTOMAC RIVER</name>
or
<Placemark>
<ExtendedData>
<SchemaData schemaUrl="#OGRGeoJSON">
<SimpleData name="DIG_NAME">POTOMAC RIVER</SimpleData>
I've tried a lot of XSLT and XML Refactoring methods, and while this seems like it should be easy, I can't figure it out. Any help would be appreciated!
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Remove KML elements that do not contain certain values
Hi,
The difficulty is in writing the XPath that describes want you want to be removed. It works with Refactoring > XML Refactoring, Delete element with the following XPath specified in the Element field:
Regards,
Adrian
The difficulty is in writing the XPath that describes want you want to be removed. It works with Refactoring > XML Refactoring, Delete element with the following XPath specified in the Element field:
Code: Select all
Placemark[not(name='POTOMAC RIVER' or ExtendedData/SchemaData[@schemaUrl="#OGRGeoJSON"]/SimpleData[@name="DIG_NAME"]="POTOMAC RIVER")]
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service