Hi Vlad,
You're right, it would be difficult to cache grammars in Xerces1. This is
largely due to the fact that Xerces1 uses a StringPool--that is, in its
grammar representation it uses integer handles instead of String
references. This is (in principle anyway) very efficient; the only trouble
is that it means that, when you parse a grammar, it becomes dependent on
that particular StringPool. Since the symbols from instance documents also
live in the StringPool--and the same one as those of the grammars that
validate the instance document--the situation becomes wellnigh insoluble.
That was one of the many reasons for moving on to Xerces2. We can actually
have a sensible grammar caching scheme there. And the more people that
help with Xerces2 the faster we'll have it too. :-)
Cheers,
Neil
Neil Graham
XML Parser Development
IBM Toronto Lab
Phone: 416-448-3519, T/L 778-3519
E-mail: [EMAIL PROTECTED]
[EMAIL PROTECTED] on 08/31/2001 11:23:57 AM
Please respond to [EMAIL PROTECTED]
To: xerces-j-user <[EMAIL PROTECTED]>
cc:
Subject: Re: Access to validator info
Hi there.
Sounds like you guys have a very good understanding of how Xerces parser
works.
Can you please tell what you think it would take and what needs to be done
in general to modify Xerces1 to cache
schema grammar and use it to validate different XML files?
I looked at doing that but it seems to me that processed schema is attached
to XML document that we are validating and it will take a lot of code
changes to separate them.
Vlad
Please respond to xerces-j-user <[EMAIL PROTECTED]>
To: xerces-j-user <[EMAIL PROTECTED]>
cc:
Subject: Re: Access to validator info
On Fri, 31 Aug 2001, Andreas [iso-8859-1] Th�nnessen wrote:
> Which parser provides the method getValidator()?
> I couldn't find it in the apidocs (Xerces-J 1.4.1/1.4.3/2.0.0.beta2)
> Do I have to set up the Grammar, XMLValidator etc. manually for a
> "customized" parser? That's what I hoped to avoid ;-)
I subclassed DOMParser:
public class MemeDOMParser
extends org.apache.xerces.parsers.DOMParser {
public StringPool getStringPool() {
return this.fStringPool;
}
public XMLValidator getValidator() {
return this.fValidator;
}
}
fValidator is protected.
> > InsertableElementsInfo info =
> > this.makeInfoObject (node);
>
> Do you construct thie InsertableElementsInfo completely new (e.g.
> based on the schema tree - should be easy), or is it possible to get
> (at least) the possibleChildren[] from where ever the
> parser/validator stored this info on parsing the DTD/schema?
I'm not sure I understand your question, but here's the relevant method.
(I probably should have just tarred the files up and sent them whole):
public InsertableElementsInfo makeInfoObject (Node n) {
InsertableElementsInfo info = new InsertableElementsInfo();
Node parent = n.getParentNode();
NodeList children = parent.getChildNodes();
int childCount = children.getLength();
info.curChildren = new QName[childCount];
info.childCount = childCount;
for (int i = 0; i < info.childCount; i++) {
Node child = children.item(i);
int index = this.getElementIndex(child.getNodeName());
info.curChildren[i] = new QName(-1, index, index);
if (child == n) {
info.insertAt = i;
info.curChildren[i] = null;
}
}
return (info);
}
> > Grammar g = val.getGrammar();
>
> Again I cannot see the method getGrammar() in the apidocs of
> XMLValidator!?
After poking around my code, I discovered that I actually added
getGrammar() to XMLValidator:
public Grammar getGrammar() {
return(this.fGrammar);
}
and made my clients use that modified version of Xerces. Ouch. Perhaps
this makes this approach unusable by you.
In general, I found that there were useful methods that I wanted to use in
Xerces, but that they were no longer supported. I could get things
working, but it took modifications (I don't think that was the only place
where I modified Xerces). I think that Xerces2 is going to support
validator access in a more direct fashion.
j
---
"Users complain that they receive too much spam, while spammers protest
messages are legal." -InfoWorld
"You do not have to do everything disagreeable that you have a right to
do." -Judith Martin (Miss Manners)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]