0

I have an XML and some struggle understanding how elements are qualified to the namespaces. Unfortunately I could not find a valid answer for my question. I have a small example to make it easier to follow my question (sorry for the German expressions):

<?xml version="1.0" encoding="utf-8"?>
<Buchempfehlungen xmlns:book="http://aifb.kit.edu/buecher"
xmlns:pub="http://aifb.kit.edu/publisher">
    <Empfehlung>
        <book:Titel>Kleines Handbuch für den Umgang mit Unwissen</book:Titel>
        <book:ISBN>978-3442749775</book:ISBN>
        <Autor xmlns="http://aifb.kit.edu/buecher">
            <Name>Nassim Nicholas Taleb</Name>
            <Geburtsdatum>1. Januar 1960</Geburtsdatum>
        </Autor>
        <Verlag>
            <pub:Name>btb</pub:Name>
            <pub:Ort>München</pub:Ort>
        </Verlag>
    </Empfehlung>
</Buchempfehlungen>

Now my question is, to which namespace is the element "Verlag" assigned? Since there is no default-namespace declaration in the root element. But there is a default in the element Autor, which is on the same "level" as "Verlag"

Does this "deeper" default-ns declaration count for the whole document or just it´s descendants?

1 Answer 1

1

The following XPath expression returns the Verlag element. Its sibling Autor default namespace doesn't affect it. Just its descendants, i.e. Name and Geburtsdatum, belong to the same default namespace xmlns="http://aifb.kit.edu/buecher".

XPath

/Buchempfehlungen/Empfehlung/Verlag

Output

<Verlag>
    <pub:Name>btb</pub:Name>
    <pub:Ort>München</pub:Ort>
</Verlag>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.