Home>
I'm new to programming.
I want to get the string in the xml tag.
Specifically, I want to get a string between
I would like to know if anyone knows it.
Thank you in advance.
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'):
, or I searched Google for error messages.
Supplemental information (FW/tool version etc.)About xml files,
35.305659750 139.505287500
35.305639250 139.505346306
This is a form with a block like this following.
-
Answer # 1
Related articles
- php - how to get the tag of the video from youtube api
- how to get tag name from c # xml file
- html - how to specify the tag width
- c# - how to use repeater tag of aspx
- how to receive c # json string
- how to save datagridview as xml file in c #
- how to get sequal pro table in java
- javascript - i want to know how to get the id when the mouse is over
- php - how to get value from the model
- html - how to tag and number of attributes
- php - how to get the value of the check box
- javascript - how to get gcaljs
- macos (osx) - how to get window handle on mac with qt
- c# - i don't know how to get the title with cefsharp
- php - how to get the body when you nest a shortcode in wordpress
- javascript - how to get from ncmb data list in object format
- postgresql - how to get last id in postgres
- javascript - how to get the destination url by clicking the link
- java - how to use mybatis tag
- python 3 how to get value in line
Trends
I downloaded and checked the XML on the same site.
If you format the XML,gml: posListis in a deep hierarchy, so it looks like'./ gml: posList'can't get it.
Have you tried writing'.// gml: posList'to get all of the children below?
This notation is called xpath. There was an explanation in the following article
http://hikm.hatenablog.com/entry/20090206/1233950923
Thegml:part is called the namespace. I don't know if this is causing the error
https://orangain.hatenablog.com/entry/namespaces-in-xpath