O'Reilly logo

XML and Java™ from scratch by Nicholas Chase

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding Namespaces

Now that we've got all our data added to the document, it's time to segregate it into namespaces so we can work with it.

When it comes to namespaces, an element or attribute can find itself in three possible situations. The first is an explicit namespace, in which the namespace is declared and a prefix is used. In a situation such as this, our orderSystem document might look like Listing 6.13.

Listing 6.13. Explicit Namespace Declarations
 0:<?xml version="1.0" encoding="UTF-8"?> 1:<orderSystem> 2: <ord:orders xmlns:ord="http://www.nicholaschase.com/orders/"> 3: <ord:order order_id="To1010mC24980190282174342At"> 4: <ord:order_status>open</ord:order_status> 5: <ord:item product_id="RC2342"> 6: <ord:quantity>5</ord:quantity> 7: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required