Namespace Attributes

Discussion in 'XML' started by geoff, Dec 3, 2007.

  1. geoff

    geoff Guest

    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
     
    geoff, Dec 3, 2007
    #1
    1. Advertising

  2. geoff wrote:
    > 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.





    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 3, 2007
    #2
    1. Advertising

  3. In article <IpX4j.54803$>,
    geoff <> wrote:

    >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
    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
     
    Richard Tobin, Dec 3, 2007
    #3
  4. geoff

    geoff Guest

    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?

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



    --g
     
    geoff, Dec 3, 2007
    #4
  5. geoff wrote:
    > 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.


    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Dec 3, 2007
    #5
  6. geoff

    geoff Guest

    > 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="" to=""
    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>
     
    geoff, Dec 4, 2007
    #6
  7. geoff

    geoff Guest

    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
     
    geoff, Dec 4, 2007
    #7
  8. In article <zT25j.193237$>,
    geoff <> wrote:

    >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
    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
     
    Richard Tobin, Dec 4, 2007
    #8
  9. geoff wrote:
    > 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.)

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Dec 4, 2007
    #9
  10. 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.)

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Dec 4, 2007
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Max
    Replies:
    1
    Views:
    516
    Joe Kesselman
    Sep 22, 2006
  2. P4trykx
    Replies:
    2
    Views:
    1,891
    bruce barker
    Jan 31, 2007
  3. james_027

    class attributes & data attributes

    james_027, Jun 20, 2007, in forum: Python
    Replies:
    2
    Views:
    412
    Bruno Desthuilliers
    Jun 20, 2007
  4. Kyle Schmitt
    Replies:
    3
    Views:
    228
    Kyle Schmitt
    Jul 24, 2007
  5. Jayden
    Replies:
    16
    Views:
    561
    Steven D'Aprano
    Sep 29, 2012
Loading...

Share This Page