Java Reference
In-Depth Information
Creating a SOAP Element with a Qualified Name
Problem
You need to add an element to a SOAP message that you're building, and it needs to have a
namespace URI, a prefix, and a local part.
Solution
Use a javax.xml.namespace.QName , which represents a qualified name, and allows you to
define a namespace URI, a prefix, and a local part.
Discussion
QName s are new with Java SE 5, replacing the older Name class. They are immutable, and there-
fore must be wholly created using the constructor.
Let's recall the basic components of an XML qualified name, using the following element as
a model:
QName bodyName = new QName("http://example.com", "getQuote", "e");
This name defines a namespace URI, a local part, and a prefix:
▪ The namespace URI is “http://example.com”, which acts somewhat like a Java package in
that it demarcates a logical division of a set of elements as distinct from some other set.
They allow multiple elements with the same name but different properties to contain the
same local part but not collide during processing.
▪ The local part is “getQuote”, which defines the element name.
▪ The prefix is “e”. It is not meaningful in the document, but used only as a shortcut pointer
to the namespace.
That will result in an XML element that looks like this:
<e:getQuote xmlns:e="http://example.com">
You can also create a QName that uses only the namespace URI and the local part, as is some-
times required by public web services. For example, the WebServicesX services, written in
.NET, use this format:
QName portQName = new QName("http://www.webserviceX.NET/",
"StockQuoteSoap");
Search WWH ::




Custom Search