|
Technical Interview Questions
Javascript Interview Questions
Oracle Interview Questions
XHtml Interview Questions
Ajax
Interview Questions
CSS Interview Questions
VB
Interview Questions
.........More
Programming Source Codes
Java Source Codes
Html Source Codes
CSS Source Codes
C Source Codes
.........More
Soft Skills
Communication Skills
Leadership Skills
.........More
|
|
XML Interview Questions and Answers
How do applications process documents that use XML
namespaces?
Applications process documents that use XML namespaces
in almost exactly the same way they process documents
that don't use XML namespaces. For example, if a
namespace-unaware application adds a new sales order to
a database when it encounters a SalesOrder element, the
equivalent namespace-aware application does the same.
The only difference is that the namespace-aware
application:
* Might need to check for xmlns attributes and parse
qualified names. Whether it does this depends on whether
such processing is already done by lower-level software,
such as a namespace-aware DOM implementation.
* Uses universal (two-part) names instead of local
(one-part) names. For example, the namespace-aware
application might add a new sales order in response to
an {http://www.google.com/ito/sales}SalesOrder element
instead of a SalesOrder element.
How do I use XML namespaces with SAX 1.0?
The easiest way to use XML namespaces with SAX 1.0 is to
use John Cowan's Namespace SAX Filter (see http://www.ccil.org/~cowan/XML).
This is a SAX filter that keeps track of XML namespace
declarations, parses qualified names, and returns
element type and attribute names as universal names in
the form:
URI^local-name
For example:
http://www.google.com/ito/sales^SalesOrder
Your application can then base its processing on these
longer names. For example, the code:
public void startElement(String elementName,
AttributeList attrs)
throws SAXException
{
...
if (elementName.equals("SalesOrder"))
{
// Add new database record.
}
...
}
might become:
public void startElement(String elementName,
AttributeList attrs)
throws SAXException
{
...
if (elementName.equals("http://www.google.com/sales^SalesOrder"))
{
// Add new database record.
}
...
}
or:
public void startElement(String elementName,
AttributeList attrs)
throws SAXException
{
...
// getURI() and getLocalName() are utility functions
// to parse universal names.
if (getURI(elementName).equals("http://www.foo.com/ito/sales"))
{
if (getLocalName(elementName).equals("SalesOrder"))
{
// Add new database record.
}
}
...
}
If you do not want to use the Namespace SAX Filter, then
you will need to do the following in addition to
identifying element types and attributes by their
universal names:
* In startElement, scan the attributes for XML namespace
declarations before doing any other processing. You will
need to maintain a table of current prefix-to-URI
mappings (including a null prefix for the default XML
namespace).
* In startElement and endElement, check whether the
element type name includes a prefix. If so, use your
mappings to map this prefix to a URI. Depending on how
your software works, you might also check if the local
part of the qualified name includes any colons, which
are illegal.
* In startElement, check whether attribute names include
a prefix. If so, process as in the previous point.
How do I use XML namespaces with SAX 2.0?
SAX 2.0 primarily supports XML namespaces through the
following methods: * startElement and endElement in the
ContentHandler interface return namespace names (URIs)
and local names as well as qualified names. * getValue,
getType, and getIndex in the Attributes interface can
retrieve attribute information by namespace name (URI)
and local name as well as by qualified name.
Page Numbers
: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Have a Question ?
post your questions here. It
will be answered as soon as possible.
Check
HTML Interview
Questions for more HTML Interview Questions with Answers
Check
JDBC Interview
Questions for more JDBC Interview Questions with Answers
Check
Job Interview Questions
for more Interview Questions with Answers
|