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.
Applicable source code
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.
<? 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,
This is a form with a block like this following.
Answer # 1
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
gml:part is called the namespace. I don't know if this is causing the error
- how to get tag name from c # xml file
- php - how to get the tag of the video from youtube api
- c # - i want to get how many rows were updated when i did update
- php - how to get the value of the check box
- how to get the current time in firebase
- php - i want to know how to get the sql in clause like and concatenation
- how to receive c # json string
- how to save datagridview as xml file in c #
- how to get sequal pro table in java
- php - how to get value from the model
- html - how to tag and number of attributes
- macos (osx) - how to get window handle on mac with qt
- how to get php value
- c# - how to use repeater tag of aspx
- php - how to get the body when you nest a shortcode in wordpress
- c# - i don't know how to get the title with cefsharp
- postgresql - how to get last id in postgres
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- python - you may need to restart the kernel to use updated packages error
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- xcode - pod install [!] no `podfile 'found in the project directory
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- i want to call a child component method from a parent in vuejs