Thread XML -> Namespaces (0 answers)
Opened by leo11 at 2010-02-18 07:58

leo11
 2010-02-18 07:58
#133230 #133230
User since
2008-08-14
250 Artikel
BenutzerIn
[default_avatar]
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" ?>
<Kunden xmlns:adr="http://www.google.de/search"
xmlns="http://www.default.com">
<adr:Kunde id="9999">
<Name>Meier</Name>
<Vorname>Peter</Vorname>
<Umsatz>1423</Umsatz>
<Kaeufe>28</Kaeufe>
</adr:Kunde>
<Kunde id="45326">
<Name>Schmidt</Name>
<Vorname>Harald</Vorname>
<Umsatz>7421.00</Umsatz>
<Kaeufe>19</Kaeufe>
</Kunde>
<Kunde id="45327">
<Name>Weinberg</Name>
<Vorname>Simon</Vorname>
<Umsatz>5742.94</Umsatz>
<Kaeufe>23</Kaeufe>
</Kunde>
</Kunden>


Bei w3c heißt es:
Quote
A default namespace declaration applies to all unprefixed element names within its scope. Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear.


Ist damit id="9999" im Default-Namespace, in adr oder in keinem?
In welchem Namespace sind die anderen id's?
In welchem namespace ist <Name>Meier</Name>?

Auf der Suche nach einer Antwort habe ich mit xmllint experimentiert:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
pc01:/tmp$ xmllint --shell a.xml
/ > cd /Kunden/Kunde
/Kunden/Kunde is a 2 Node Set
/ > cd /Kunden/Kunde[1]
Kunde > cat
<Kunde id="45326">
<Name>Schmidt</Name>
<Vorname>Harald</Vorname>
<Umsatz>7421.00</Umsatz>
<Kaeufe>19</Kaeufe>
</Kunde>
Kunde > cd /Kunden/adr:Kunde
XPath error : Undefined namespace prefix
xmlXPathEval: evaluation failed
/Kunden/adr:Kunde: no such node
Kunde >


Wie wähle ich hier adr:Kunde aus?

Kennt ihr einen Weg mit diesem Tool oder einem anderen die Namespaces "sichtbar" zu machen. So dass man eine Ausgabe in der Art erhält:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" ?>
<{http://www.default.com}Kunden xmlns:adr="http://www.google.de/search"
xmlns="http://www.default.com">
<{http://www.google.de/search}:Kunde id="9999">
<Name>Meier</Name>
<Vorname>Peter</Vorname>
<Umsatz>1423</Umsatz>
<Kaeufe>28</Kaeufe>
</{http://www.google.de/search}:Kunde>
<{http://www.default.com}Kunde {http://www.default.com}id="45326">
<{http://www.default.com}Name>Schmidt</{http://www.default.com}Name>
<{http://www.default.com}Vorname>Harald</{http://www.default.com}Vorname>
<{http://www.default.com}Umsatz>7421.00</{http://www.default.com}Umsatz>
<{http://www.default.com}Kaeufe>19</{http://www.default.com}Kaeufe>
</{http://www.default.com}Kunde>
<{http://www.default.com}Kunde {http://www.default.com}id="45327">
<{http://www.default.com}Name>Weinberg</{http://www.default.com}Name>
<{http://www.default.com}Vorname>Simon</{http://www.default.com}Vorname>
<{http://www.default.com}Umsatz>5742.94</{http://www.default.com}Umsatz>
<{http://www.default.com}Kaeufe>23</{http://www.default.com}Kaeufe>
</{http://www.default.com}Kunde>
</{http://www.default.com}Kunden>


In man xmllint steht:
Quote
dir PATH
Dumps information about the node (namespace, attributes, content).

Leider erlange ich damit keine Antworten.. .

View full thread XML -> Namespaces