<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><HTML><head><META content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<title></title>
</head><BODY>
<DIV>
<font size="-1">You have it spot on...<br>
<br>
some comments:<br>
<br>
I based the code on the CVS repo.... because that's what I had set
up at work... (I did this on the train in to work, and then sent
it from there....). But, even if I look at the Git repo (on the
1.1.1 branch), it's line 574<br>
<br>
<a class="moz-txt-link-freetext" href="https://github.com/hunterhacker/jdom/blob/jdom-1.1.1/core/src/java/org/jdom/input/SAXHandler.java">https://github.com/hunterhacker/jdom/blob/jdom-1.1.1/core/src/java/org/jdom/input/SAXHandler.java</a><br>
<br>
There will need to be a corresponding fox for JDOM2. You have the
issue targeted at 'milestone 1.1.2', so I worked off that. It
feels very weird writing code without generics! (and writing
JUnit3 tests...).<br>
<br>
As an aside, how do you intend to do 'future' 1.1.* releases (if
any)? Using the Git repo or the original CVS? I see advantages to
each...<br>
<br>
<br>
I should double-check the DOMBuilder but in theory it should all
be correct in whatever made the DOM model.<br>
<br>
I just did the check, and, indeed, there should be no problem with
it.... in the sense that by the time something is DOM, it should
be right!<br>
<br>
I'll run a DOM version of the code on the same input, and see what
comes up... there could be a gremlin I suppose.<br>
<br>
I wrote the patch/code based on a Java6VM have installed at
work... I should double-check it against 1.2 too.<br>
<br>
Did you intend to mail offlist?<br>
<br>
Rolf<br>
<br>
<br>
</font><br>
On 08/09/2011 07:14 PM, Jason Hunter wrote:
<blockquote cite="mid:38CA00BB-AFF4-4ED7-BAFE-D4465BADB6FD@servlets.com" type="cite">I assume you mean line 568?
<div><br>
</div>
<div>I'll add some comments inline and you can tell me if I'm
following the logic right.</div>
<div><br>
<div>
<blockquote type="cite">
<div>
<div><font size="-1"><br>
</font><font size="-1"> } else if
(atts.getURI(i) != null &&
atts.getURI(i).length() > 0) {<br>
// the localname and qName are the
same, but there is a<br>
// Namspace URI. We need to figure out
the namespace prefix.<br>
// this is an unusual condition.
Currently the only known trigger<br>
// is when there is a fixed/defaulted
attribute from a validating<br>
// XMLSchema, and the attribute is in
a different namespace<br>
// than the rest of the document, this
happens whenever there<br>
// is an attribute definition that has
form="qualified".<br>
// <xs:attribute name="attname"
form="qualified" ... /><br>
// or the schema sets
attributeFormDefault="qualified"<br>
</font></div>
</div>
</blockquote>
<div><br>
</div>
<div>// The goal of this searching code is to find a good
attNS namespace we can use.</div>
<br>
<blockquote type="cite">
<div>
<div><font size="-1"> String attURI =
atts.getURI(i);<br>
Namespace attNS = null;<br>
Element p = element;<br>
// We need to ensure that a particular
prefix has not been<br>
// overridden at a lower level than
what we are expecting.<br>
// track all prefixes to ensure they
are not changed lower<br>
// down.<br>
HashSet overrides = new HashSet();<br>
uploop: do {<br>
// Search up the Element tree
looking for a prefixed namespace<br>
// matching our attURI<br>
</font></div>
</div>
</blockquote>
<div><br>
</div>
<div>// First look at the element itself</div>
<br>
<blockquote type="cite">
<div>
<div><font size="-1"> if
(p.getNamespace().getURI().equals(attURI)<br>
&&
!overrides.contains(p.getNamespacePrefix())<br>
&&
!"".equals(element.getNamespace().getPrefix())) {<br>
// we need a prefix. It's
impossible to have a namespaced<br>
// attribute if there is no
prefix for that attribute.<br>
attNS = p.getNamespace();<br>
break uploop;<br>
}<br>
</font></div>
</div>
</blockquote>
<div><br>
</div>
// Then any additional namespaces defined on the element</div>
<div><br>
<blockquote type="cite">
<div>
<div><font size="-1">
overrides.add(p.getNamespacePrefix());<br>
for (Iterator it =
p.getAdditionalNamespaces().iterator(); <br>
it.hasNext(); ) {<br>
Namespace ns =
(Namespace)it.next();<br>
if
(!overrides.contains(ns.getPrefix())<br>
&&
attURI.equals(ns.getURI())) {<br>
attNS = ns;<br>
break uploop;<br>
}<br>
overrides.add(ns.getPrefix());<br>
}<br>
</font></div>
</div>
</blockquote>
<div><br>
</div>
<div>// If we haven't hit something yet, keep walking up the
tree</div>
<br>
<blockquote type="cite">
<div>
<div><font size="-1"> if (p ==
element) {<br>
p = currentElement;<br>
} else {<br>
p = p.getParentElement();<br>
}<br>
} while (p != null);<br>
</font></div>
</div>
</blockquote>
<div><br>
</div>
<div>// If we still don't have attNS we need to invent a
unique one</div>
<br>
<blockquote type="cite">
<div>
<div><font size="-1"> if (attNS == null) {<br>
// we cannot find a 'prevailing'
namespace that has a prefix<br>
// that is for this namespace.<br>
// This basically means that
there's an XMLSchema, for the<br>
// DEFAULT namespace, and there's
a defaulted/fixed<br>
// attribute definition in the
XMLSchema that's targeted<br>
// for this namespace,... but, the
user has either not<br>
// declared a prefixed version of
the namespace, or has<br>
// re-declared the same prefix at
a lower level with a<br>
// different namespace.<br>
// All of these things are
possible.<br>
// Create some sort of default
prefix.<br>
int cnt = 0;<br>
String base = "attns";<br>
String pfx = base + cnt;<br>
while (overrides.contains(pfx)) {<br>
cnt++;<br>
pfx = base + cnt;<br>
}<br>
attNS =
Namespace.getNamespace(pfx, attURI);<br>
}<br>
</font></div>
</div>
</blockquote>
<div><br>
</div>
<div>Finally build the attribute, using either a found attNS
or an invented one</div>
<br>
<blockquote type="cite">
<div>
<div><font size="-1"> attribute =
factory.attribute(attLocalName, atts.getValue(i),<br>
attType, attNS);<br>
} else {<br>
</font></div>
</div>
</blockquote>
</div>
<br>
</div>
<div>Lastly, DOMBuilder needs code like this too, no?</div>
<div><br>
</div>
<div>-jh-</div>
<div><br>
</div>
</blockquote>
</DIV>
<DIV> </DIV>
<DIV STYLE="FONT-SIZE: 9pt; FONT-FAMILY: Courier New">
<HR>
<DIV ALIGN="justify" STYLE="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"><FONT FACE="Arial" SIZE="1">This email and any files transmitted with it are confidential and proprietary to Algorithmics Incorporated and its affiliates ("Algorithmics"). If received in error, use is prohibited. Please destroy, and notify sender. Sender does not waive confidentiality or privilege. Internet communications cannot be guaranteed to be timely, secure, error or virus-free. Algorithmics does not accept liability for any errors or omissions. Any commitment intended to bind Algorithmics must be reduced to writing and signed by an authorized signatory.</FONT></DIV>
<HR>
<DIV></DIV></DIV></BODY></HTML>