Home>

I'm new to programming.
I want to get the string in the xml tag.
Specifically, I want to get a string between~in the xml file below.
I would like to know if anyone knows it.
Thank you in advance.

Error message If i move the python source code under

Traceback (most recent call last):
  File "C: \ ProgramData \ Anaconda3 \ lib \ xml \ etree \ ElementPath.py", line 263, in iterfind
    selector = _cache [cache_key]
KeyError: ('./gml:posList', None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C: \ ProgramData \ Anaconda3 \ lib \ xml \ etree \ ElementPath.py", line 80, in xpath_tokenizer
    raise KeyError
KeyError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "swe5_xml_enoshima.py", line 38, in<module>
    for i in root.findall ('./ gml: posList'):
  File "C: \ ProgramData \ Anaconda3 \ lib \ xml \ etree \ ElementPath.py", line 304, in findall
    return list (iterfind (elem, path, namespaces))
  File "C: \ ProgramData \ Anaconda3 \ lib \ xml \ etree \ ElementPath.py", line 283, in iterfind
    token = next ()
  File "C: \ ProgramData \ Anaconda3 \ lib \ xml \ etree \ ElementPath.py", line 83, in xpath_tokenizer
    raise SyntaxError ("prefix% r not found in prefix map"% prefix)
SyntaxError: prefix 'gml' not found in prefix map
I get an error.
Applicable source code
<? xml version = "1.0" encoding = "utf-8"?>
<Dataset xsi: schemaLocation = "http://fgd.gsi.go.jp/spec/2008/FGD_GMLSchema FGD_GMLSchema.xsd"
    xmlns: gml = "http://www.opengis.net/gml/3.2"
    xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
    xmlns: xlink = "http://www.w3.org/1999/xlink"xmlns = "http://fgd.gsi.go.jp/spec/2008/FGD_GMLSchema"
    gml: id = "Dataset1">
  <gml: description>Base map information metadata ID = fmdid: 18-1001</gml: description>
  <gml: name>Base map information download data (GML version)</gml: name>
<Cstline gml: id = "K14_5022012708_1">
<fid>50220-12708-s-2392</fid>
<lfSpanFr gml: id = "K14_5022012708_1-1">
<gml: timePosition>2016-11-15</gml: timePosition>
</lfSpanFr>
<devDate gml: id = "K14_5022012708_1-2">
<gml: timePosition>2018-10-02</gml: timePosition>
</devDate>
<orgGILvl>2500</orgGILvl>
<loc>
<gml: Curve gml: id = "K14_5022012708_1-g" srsName = "fguuid: jgd2011.bl">
<gml: segments>
<gml: LineStringSegment>
<gml: posList>
35.305659750 139.505287500
35.305639250 139.505346306
</gml: posList>
</gml: LineStringSegment>
</gml: segments>
</gml: Curve>
</loc>
<type>Other</type>
</Cstline>
...
import xml.etree.ElementTree as ET
# Parse XML file
tree = ET.parse ('C: \\ Users \\ root \\ Documents \\ xml_sax_0003x \\ data \\ Cstline \\ FG-GML-523973-Cstline-20190701-0001.xml')
m = 0
# Get XML
root = tree.getroot ()
for i in root.findall ('./ gml: posList'):print (i.attrib)
    m + = 1
print (m)

With python code

for i in root.findall ('./ gml: posList'):

for i in root.findall ('./ posList'):

I tried to change it to

, or I searched Google for error messages.

Supplemental information (FW/tool version etc.)

About xml files,


50220-12708-s-2392

2016-11-15


2018-10-02

2500





35.305659750 139.505287500
35.305639250 139.505346306





Other

This is a form with a block like this following.