0

I have an XML string which looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:geonode="http://www.geonode.org/" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" targetNamespace="http://www.geonode.org/">
  <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://localhost:8080/geoserver/schemas/gml/3.1.1/base/gml.xsd"/>
  <xsd:complexType name="test_24Type">
    <xsd:complexContent>
      <xsd:extension base="gml:AbstractFeatureType">
        <xsd:sequence>
          <xsd:element maxOccurs="1" minOccurs="0" name="attribute_1" nillable="true" type="xsd:string"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="the_geom" nillable="true" type="gml:MultiLineStringPropertyType"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:element name="test_24" substitutionGroup="gml:_Feature" type="geonode:test_24Type"/>
</xsd:schema>

What I want to do is to use Python in order to extract the url corresponding to xmlns:geonode:

"http://www.geonode.org/"

I know there is this library: from xml.etree import cElementTree as ET But I am not sure how to use it properly in order to extract information which is on this element.

1 Answer 1

-1

The following is one of the ways to extract data from xml file using xml.etree library and python 2.7. Replace the xml file name and the tag name in the corresponding places in the code.

import xml.etree.ElementTree as XT
dataTree = XT.parse('your_xml_file_name.xml')
dataRoot = dataTree.getroot()
geoNode = dataRoot.find('your_tag_name').text
print geoNode
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. I do not have a file but a variable which the XML string is stored.
In that case you can use the variable name in the place of the file name. Please see these answers for more detailed solutions: link
The question is about extracting http://www.geonode.org/ from the xmlns:geonode="http://www.geonode.org/" namespace declaration. This code does not do that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.