Scott Sauyet wrote:
[color=blue]
> It took me a while to chase down what the Crimson parser was talking
> about with this exception: "java.lang.IllegalStateException: can't
> declare any more prefixes in this context", but I got it. It means
> that it wants to see no attributes defined before the namespace
> attribution declaration. For instance,
>
> <myns:element name="xyz" xmlns:myns="this fails" ... >
>
> <myns:element xmlns:myns="this works" name="xyz" ... >
>
> A developer working for a client tells me that this restriction is
> "straight out of the XML spec", but I can't find a reference anywhere.
> I was wondering if I'm missing something, or if this is true. I
> thought the namespace declaration was treated like any other attribute.
> Any pointer to a reference confirming or refuting that point would be
> appreciated.[/color]
Frankly I don't think it is true. First of all the XML specification
does not deal with namespaces at all, there is a separate specification
doing that, and the section here
<http://www.w3.org/TR/REC-xml-names/#nsc-NSDeclared>
in my view obviously allows both constructs you have above. All it says
is that a prefix has to be declared in the start tag of the element
itself or an ancestor but there is no requirement that namespace prefix
declararing attributes need to come first.
Furthermore I have tried the following simple XML
<?xml version="1.0" encoding="UTF-8"?>
<root xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" />
with Crimson in Java JDK 1.4.2_06 as follows without problems:
DocumentBuilderFactory docBuilderFactory =
DocumentBuilderFactory.newInstance();
docBuilderFactory.setNamespaceAware(true);
System.out.println("DocumentBuilderFactory: " + docBuilderFactory);
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
System.out.println("DocumentBuilder: " + docBuilder);
Document xmlDocument = docBuilder.parse(args[0]);
Element rootElement = xmlDocument.getDocumentElement();
for (int i = 0, length = rootElement.getAttributes().getLength();
i < length; i++) {
Attr attributeNode = (Attr) rootElement.getAttributes().item(i);
System.out.println("Attribute " + i + ": name: " +
attributeNode.getNodeName() + "; value: " + attributeNode.getNodeValue());
}
The output is
DocumentBuilderFactory:
org.apache.crimson.jaxp.DocumentBuilderFactoryImpl @11a698a
DocumentBuilder: org.apache.crimson.jaxp.DocumentBuilderImpl@17943a 4
Attribute 0: name: xlink:type; value: simple
Attribute 1: name: xmlns:xlink; value:
http://www.w3.org/1999/xlink
so Crimson parses the XML document without problems.
--
Martin Honnen
http://JavaScript.FAQTs.com/