Namespace Attributes

G

geoff

In the following fragment, elements like 'item' and 'description' would be
in the 'po' namespace but the attribute 'p:priority="high" ' would be in the
'p' namespace?

<po:po id="43871"
submitted="2004-01-05"
customerId="73852"
xmlns:po="http://www.skatestown.com/ns/po"
xmlns:p="http://www.skatestown.com/ns/priority">
. . .
<po:eek:rder>
<item sku="318-BP" quantity="5" p:priority="high">
<description>Skateboard backpack; five
pockets</description>

.. . . so, if an order processor could handle this xml and later on,
'priority' was added, this would not break the processor since priority is
in its own namespace?

Thanks.

--g
 
M

Martin Honnen

geoff said:
In the following fragment, elements like 'item' and 'description' would be
in the 'po' namespace but the attribute 'p:priority="high" ' would be in the
'p' namespace?

<po:po id="43871"
submitted="2004-01-05"
customerId="73852"
xmlns:po="http://www.skatestown.com/ns/po"
xmlns:p="http://www.skatestown.com/ns/priority">
. . .
<po:eek:rder>
<item sku="318-BP" quantity="5" p:priority="high">
<description>Skateboard backpack; five
pockets</description>

. . . so, if an order processor could handle this xml and later on,
'priority' was added, this would not break the processor since priority is
in its own namespace?

item and description element are in no namespace in your snippet. The
sku and quantity attribute are in no namespace, the priority attribute
is in the http://www.skatestown.com/ns/priority namespace.
 
R

Richard Tobin

geoff said:
In the following fragment, elements like 'item' and 'description' would be
in the 'po' namespace but the attribute 'p:priority="high" ' would be in the
'p' namespace?

<po:po id="43871"
submitted="2004-01-05"
customerId="73852"
xmlns:po="http://www.skatestown.com/ns/po"
xmlns:p="http://www.skatestown.com/ns/priority">
. . .
<po:eek:rder>
<item sku="318-BP" quantity="5" p:priority="high">
<description>Skateboard backpack; five
pockets</description>

No, item and description are in no namespace.
. . . so, if an order processor could handle this xml and later on,
'priority' was added, this would not break the processor since priority is
in its own namespace?

Using namespaced attributes is certainly a way to add attributes whose
interpretation does not come from the element they're on, provided
that your schema (or whatever) allows such other-namespace attributes.

-- Richard
 
G

geoff

With priority and the priority attribute gone, only the 'po' namespace
remains in the 'po:po' element, does item and description fall into that
namespace or they are still not in any namespace?


--g
 
J

Joseph Kesselman

geoff said:
With priority and the priority attribute gone, only the 'po' namespace
remains in the 'po:po' element, does item and description fall into that
namespace or they are still not in any namespace?

If an element or attribute does not have a prefix, and (for elements
only) is not in the scope of a Default Namespace Declaration, the
element or attribute is not in any namespace.

See the namespaces spec or a good modern XML tutorial.
 
G

geoff

See the namespaces spec or a good modern XML tutorial.

I thought I was using a good tutorial, 'Building Web Services with Java',
and amazon reviewers praised this book but it appears to have many errors.

The snippet below had 'po' in front of 'billTo', 'shipTo', 'order', etc. but
they say by moving the 'po' namespace definition to the 'po:po' element, the
child elements fall into that namespace:

http://87.249.105.167/mirror/buildingwebserviceswithjava/0672321815_ch02lev1sec4.html#ch02list08


================================================

'We can use this to further clean up the composed XML document
by moving the PO namespace declaration to the po element

Listing 2.8 Using Nested Namespace Defaulting'

<message from="(e-mail address removed)" to="(e-mail address removed)"
sent="2001-10-05" xmlns="http://www.xcommercemsg.com/ns/message">
<text>
Hi, here is what I need this time. Thx, BJ.
</text>
<attachment>
<description>The PO</description>
<item>
<po:po id="43871" submitted="2001-10-05"
xmlns:po="http://www.skatestown.com/ns/po">
<billTo id="addr-1">
...
</billTo>
<shipTo href="addr-1"/>
<order>
...
</order>
</po:po>
</item>
</attachment>
</message>
 
G

geoff

The book, 'Building Web Services with Java', has nine authors, here is
the background of one of them (from the book):

'Paul Fremantle is a Senior Technical Staff Member in IBM's Software
division, based in the Hursley Park laboratory near Winchester in England.
Paul works on IBM's Enterprise Service Bus initiative and other Web services
activities in the WebSphere product. Paul has been working on Web services
and XML at IBM since 1999, when he wrote early XML utilities for IBM's
alphaWorks website. Since then he has co-authored The XML Files, an IBM
redbook, as well as a number of articles on J2EE and Web services both in
print and on the Web. Paul's involvement on the WebSphere Application Server
includes architectural responsibility for the first SOAP support, the Web
Services Invocation Framework, and the Web Services Gateway. Paul is the
co-lead of the JWSDL standard in the Java Community Process and has
initiated two open-source projects. Paul has an MSc in computation and an MA
in mathematics and philosophy, both from Balliol College, Oxford.'


.. . . given a background like that, one would think they know something
about XML. Some of the authors consult also but they do not know the
fundamentals, it makes me wonder about the quality of their consulting.


--tc
 
R

Richard Tobin

geoff said:
The snippet below had 'po' in front of 'billTo', 'shipTo', 'order', etc. but
they say by moving the 'po' namespace definition to the 'po:po' element, the
child elements fall into that namespace:

That's not true, in particular this statement:

... the content of any namespace-prefixed element is considered to
belong to the namespace of its parent element ...

But there's something like it that is true. Namespaces are a notation
used to determine the interpretation of elements and attributes. The
responsibility for doing that determination rests with the application
that's processing the file. The obvious approach is to say that the
application interprets elements in some particular namespace (or group
of namespaces) as belonging to it, and treats others as uninterpreted
data. But some applications treat no-namespace children of their
elements as also belonging to the application, even though they're not
in its namespace.

Presumably the applications that understand the "po" namespace in this
example use the second approach.

XML Schemas provides support for this way of doing things through the
elementFormDefault attribute. If this is set to "unqualified" then
the schema can validate (by local element declarations) no-namespace
children of elements in the target namespace.

-- Richard
 
J

Joseph Kesselman

geoff said:
The snippet below had 'po' in front of 'billTo', 'shipTo', 'order', etc. but
they say by moving the 'po' namespace definition to the 'po:po' element, the
child elements fall into that namespace:

If so, they're wrong. However, you could get that effect by using the
Default Namespace Declaration:

<po id="43871" submitted="2001-10-05"
xmlns="http://www.skatestown.com/ns/po">
<billTo id="addr-1">
...
</billTo>
<shipTo href="addr-1"/>
<order>
...
</order>
</po>

Note that the Default Namespace Declaration only affects elements. If
you want attributes to be in a namespace, they have to use a properly
declared prefix. (However, it is not uncommon for namespaced nodes to
expect non-namespaced attributes, so always check your particular schema
or application spec to see whether this is going to be an issue.)
 
J

Joseph Kesselman

To me, this looks like an error introduced in editing -- the authors
probably intended to introduce the Default Namespace Declaration syntax,
but somewhere in the technical editing process someone less knowledgable
made the erroneous guess that this was an error and "corrected" it.

(Having been a technical reviewer, I can see how that would happen.
Though in the case I was looking at, what the book really needed was an
expert co-author; the guy who was writing it wasn't as familiar with the
material as he should have been and the fact that English wasn't his
first language didn't help.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top