Re: Parsing a MODS-document with validation fails

Rolf Lear <[email protected]>
Newsgroups gmane.comp.java.jdom.general
Message-ID <[email protected]>
You have it spot on...

some comments:

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

https://github.com/hunterhacker/jdom/blob/jdom-1.1.1/core/src/java/org/jdom/input/SAXHandler.java

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...).

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...


I should double-check the DOMBuilder but in theory it should all be 
correct in whatever made the DOM model.

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!

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.

I wrote the patch/code based on a Java6VM have installed at work... I 
should double-check it against 1.2 too.

Did you intend to mail offlist?

Rolf



On 08/09/2011 07:14 PM, Jason Hunter wrote:
> I assume you mean line 568?
>
> I'll add some comments inline and you can tell me if I'm following the 
> logic right.
>
>>
>>             } else if (atts.getURI(i) != null && 
>> atts.getURI(i).length() > 0) {
>>                 // the localname and qName are the same, but there is a
>>                 // Namspace URI. We need to figure out the namespace 
>> prefix.
>>                 // this is an unusual condition. Currently the only 
>> known trigger
>>                 // is when there is a fixed/defaulted attribute from 
>> a validating
>>                 // XMLSchema, and the attribute is in a different 
>> namespace
>>                 // than the rest of the document, this happens 
>> whenever there
>>                 // is an attribute definition that has form="qualified".
>>                 // <xs:attribute name="attname" form="qualified" ... />
>>                 // or the schema sets attributeFormDefault="qualified"
>
> // The goal of this searching code is to find a good attNS namespace 
> we can use.
>
>>                 String attURI = atts.getURI(i);
>>                 Namespace attNS = null;
>>                 Element p = element;
>>                 // We need to ensure that a particular prefix has not 
>> been
>>                 // overridden at a lower level than what we are 
>> expecting.
>>                 // track all prefixes to ensure they are not changed 
>> lower
>>                 // down.
>>                 HashSet overrides = new HashSet();
>>                 uploop: do {
>>                     // Search up the Element tree looking for a 
>> prefixed namespace
>>                     // matching our attURI
>
> // First look at the element itself
>
>>                     if (p.getNamespace().getURI().equals(attURI)
>> && !overrides.contains(p.getNamespacePrefix())
>> && !"".equals(element.getNamespace().getPrefix())) {
>>                         // we need a prefix. It's impossible to have 
>> a namespaced
>>                         // attribute if there is no prefix for that 
>> attribute.
>>                         attNS = p.getNamespace();
>>                         break uploop;
>>                     }
>
> // Then any additional namespaces defined on the element
>
>>                     overrides.add(p.getNamespacePrefix());
>>                     for (Iterator it = 
>> p.getAdditionalNamespaces().iterator();
>>                             it.hasNext(); ) {
>>                         Namespace ns = (Namespace)it.next();
>>                         if (!overrides.contains(ns.getPrefix())
>> && attURI.equals(ns.getURI())) {
>>                             attNS = ns;
>>                             break uploop;
>>                         }
>>                         overrides.add(ns.getPrefix());
>>                     }
>
> // If we haven't hit something yet, keep walking up the tree
>
>>                     if (p == element) {
>>                         p = currentElement;
>>                     } else {
>>                         p = p.getParentElement();
>>                     }
>>                 } while (p != null);
>
> // If we still don't have attNS we need to invent a unique one
>
>>                 if (attNS == null) {
>>                     // we cannot find a 'prevailing' namespace that 
>> has a prefix
>>                     // that is for this namespace.
>>                     // This basically means that there's an 
>> XMLSchema, for the
>>                     // DEFAULT namespace, and there's a defaulted/fixed
>>                     // attribute definition in the XMLSchema that's 
>> targeted
>>                     // for this namespace,... but, the user has 
>> either not
>>                     // declared a prefixed version of the namespace, 
>> or has
>>                     // re-declared the same prefix at a lower level 
>> with a
>>                     // different namespace.
>>                     // All of these things are possible.
>>                     // Create some sort of default prefix.
>>                     int cnt = 0;
>>                     String base = "attns";
>>                     String pfx = base + cnt;
>>                     while (overrides.contains(pfx)) {
>>                         cnt++;
>>                         pfx = base + cnt;
>>                     }
>>                     attNS = Namespace.getNamespace(pfx, attURI);
>>                 }
>
> Finally build the attribute, using either a found attNS or an invented one
>
>>                 attribute = factory.attribute(attLocalName, 
>> atts.getValue(i),
>>                         attType, attNS);
>>             } else {
>
> Lastly, DOMBuilder needs code like this too, no?
>
> -jh-
>

 
--------------------------------------------------------------------------
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.
--------------------------------------------------------------------------

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.