Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
c43a666b
Kaydet (Commit)
c43a666b
authored
Mar 31, 2015
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #23729: Improve docs for ElementTree namespace parsing
üst
e7f5e147
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
8 deletions
+10
-8
xml.etree.elementtree.rst
Doc/library/xml.etree.elementtree.rst
+10
-8
No files found.
Doc/library/xml.etree.elementtree.rst
Dosyayı görüntüle @
c43a666b
...
...
@@ -290,8 +290,8 @@ Parsing XML with Namespaces
If the XML input has `namespaces
<https:
//
en
.
wikipedia
.
org
/
wiki
/
XML_namespace
>
`__, tags and attributes
with prefixes in the form ``prefix:sometag`` get expanded to
``{uri}
tag`` where the *prefix* is replaced by the full *URI*. Also,
if there is a `default namespace
``{uri}
sometag`` where the *prefix* is replaced by the full *URI*.
Also,
if there is a `default namespace
<http:
//
www
.
w3
.
org
/
TR
/
2006
/
REC-xml-names-20060816
/#
defaulting
>
`__,
that full URI gets prepended to all of the non-prefixed tags.
...
...
@@ -317,17 +317,18 @@ prefix "fictional" and the other serving as the default namespace:
</actors>
One way to search and explore this XML example is to manually add the
URI to every tag or attribute in the xpath of a *find()* or *findall()*::
URI to every tag or attribute in the xpath of a
:meth:`~Element.find` or :meth:`~Element.findall`::
root = from
_
string(xml_text)
root = fromstring(xml_text)
for actor in root.findall('{http://people.example.com}actor'):
name = actor.find('{http://people.example.com}name')
print(name.text)
for char in actor.findall('{http://characters.example.com}character'):
print(' |-->', char.text)
A
noth
er way to search the namespaced XML example is to create a
dictionary with your own prefixes and use those in the search::
A
bett
er way to search the namespaced XML example is to create a
dictionary with your own prefixes and use those in the search
functions
::
ns = {'real_person': 'http://people.example.com',
'role': 'http://characters.example.com'}
...
...
@@ -431,8 +432,9 @@ Supported XPath syntax
| ``[tag]`` | Selects all elements that have a child named |
| | ``tag``. Only immediate children are supported. |
+-----------------------+------------------------------------------------------+
| ``[tag=text]`` | Selects all elements that have a child named |
| | ``tag`` that includes the given ``text``. |
| ``[tag='text']`` | Selects all elements that have a child named |
| | ``tag`` whose complete text content, including |
| | descendants, equals the given ``text``. |
+-----------------------+------------------------------------------------------+
| ``[position]`` | Selects all elements that are located at the given |
| | position. The position can be either an integer |
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment