You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Rudolf Michalek <be...@qbizm.com> on 2000/11/29 14:57:40 UTC
How to do not expand extity references in attributes?
I need to parse XML document and create DOM structure with
unexpanded entities in attributes. It allows me write it back
with unchanged state.
I tried to find some clear solution but failed. I found only how to
patch
Xerces (1.2.2) to don't expand entities:
I comment some lines of code for recognizing entities
in class org.apache.xerces.framework.XMLDocumentScanner
inside method scanAttValue(...)
It works fine, but it is very unclean solution.
I hope that somebody will be able to advice me some better solution.
--
Rudolf 'beren' Michalek Qbizm technologies, Inc.
Developer ... the art of internet.
________________________________________________________________________
Kralovopolska 139 tel: +420 5 4124 2414
601 12 Brno, CZ http://www.qbizm.com fax: +420 5 4121 2696
Re: How to do not expand extity references in attributes?
Posted by Petr Kuzel <Pe...@netbeans.com>.
Sebastien Ponce wrote:
>
> I've just run into the same problem and I found the same solution.
> What I would suggest is to add a feature to xerces called expand-entity-ref
> that would be used in this place to expand or not entities.
>
> Sebastien
>
> Rudolf Michalek wrote:
>
> > I need to parse XML document and create DOM structure with
> > unexpanded entities in attributes. It allows me write it back
> > with unchanged state.
Hello,
I have just posted a requirement that could solve this issue too.
See subject Xerces_J_2 feature proposal.
What's your opinion?
Ccc
--
<address>
<a href="mailto:pkuzel@netbeans.com">Petr Kuzel</a>, Sun Microsystems
: <a href="http://www.sun.com/forte/ffj/ie/">Forte Tools</a>
: XML and <a href="http://jini.netbeans.org/">Jini</a> modules</address>
Re: How to do not expand extity references in attributes?
Posted by Sebastien Ponce <se...@cern.ch>.
> I think I understand why you're asking this but do you really realize
> the implications though? Everytime we add a feature we add some ifs into
> the code, which impacts the performance. I guess this one would only
> affect the code handling entity refs which may not be so bad. But this
> raises the general question of what Xerces is designed for.
I fully agree.
> There are two main categories of XML applications:
> 1) consuming applications - applications that extract data from an XML
> document and want the document as cooked as possible.
> 2) transforming applications - applications that perform some kind of
> modification to an XML document and would like to get the new document
> as identical as the original one as possible, apart from what is
> effectively changed.
>
> Clearly Xerces wasn't designed for the latter. It would require
> transmitting a lot more information than we currently do (like what type
> of quotes was used for an attribute, the order of the attributes,
> etc...) Of course, you may tell me "oh, I don't care about that", but
> I'm sure somebody else will. So, how do we decide what to support?
> I really don't know.
Even if xerces wasn't design for transforming applications, I think that the
parse + serialize operation should lead to a file similar to the original one,
which is not the case at this time, since the entity are expanded in the
operation. Actually, I should rather say that the serialize + parse operation
should lead to a tree similar to the original one, which supposes that entities
are not expanded but allows to remove spaces and such meaningless nodes.
Another point is that xerces, at this time, does not create entityref nodes for
entity references inside attributes (see DOMParser, line ~1335). I told Andy
that I would try to implement that when I have time and I'm still trying to find
some. This would at least make a difference between attribtutes using entity
references and others.
Sebastien Ponce
Re: How to do not expand extity references in attributes?
Posted by Arnaud Le Hors <le...@us.ibm.com>.
Sebastien Ponce wrote:
>
> I've just run into the same problem and I found the same solution.
> What I would suggest is to add a feature to xerces called expand-entity-ref
> that would be used in this place to expand or not entities.
>
> Sebastien
>
> Rudolf Michalek wrote:
>
> > I need to parse XML document and create DOM structure with
> > unexpanded entities in attributes. It allows me write it back
> > with unchanged state.
> >
> > I tried to find some clear solution but failed. I found only how to
> > patch
> > Xerces (1.2.2) to don't expand entities:
> > I comment some lines of code for recognizing entities
> > in class org.apache.xerces.framework.XMLDocumentScanner
> > inside method scanAttValue(...)
> > It works fine, but it is very unclean solution.
> >
> > I hope that somebody will be able to advice me some better solution.
I think I understand why you're asking this but do you really realize
the implications though? Everytime we add a feature we add some ifs into
the code, which impacts the performance. I guess this one would only
affect the code handling entity refs which may not be so bad. But this
raises the general question of what Xerces is designed for.
There are two main categories of XML applications:
1) consuming applications - applications that extract data from an XML
document and want the document as cooked as possible.
2) transforming applications - applications that perform some kind of
modification to an XML document and would like to get the new document
as identical as the original one as possible, apart from what is
effectively changed.
Clearly Xerces wasn't designed for the latter. It would require
transmitting a lot more information than we currently do (like what type
of quotes was used for an attribute, the order of the attributes,
etc...) Of course, you may tell me "oh, I don't care about that", but
I'm sure somebody else will. So, how do we decide what to support?
I really don't know.
--
Arnaud Le Hors - IBM Cupertino, XML Technology Group
Re: How to do not expand extity references in attributes?
Posted by Sebastien Ponce <se...@cern.ch>.
I've just run into the same problem and I found the same solution.
What I would suggest is to add a feature to xerces called expand-entity-ref
that would be used in this place to expand or not entities.
Sebastien
Rudolf Michalek wrote:
> I need to parse XML document and create DOM structure with
> unexpanded entities in attributes. It allows me write it back
> with unchanged state.
>
> I tried to find some clear solution but failed. I found only how to
> patch
> Xerces (1.2.2) to don't expand entities:
> I comment some lines of code for recognizing entities
> in class org.apache.xerces.framework.XMLDocumentScanner
> inside method scanAttValue(...)
> It works fine, but it is very unclean solution.
>
> I hope that somebody will be able to advice me some better solution.
Validating XML docs against schema
Posted by Vanessa D Johnson <va...@jpl.nasa.gov>.
Hello:
Is there a class in the xerces API that enables one to validate an XML
document against a particular schema?
Thanks,
Vanessa Johnson
Re: getOwnerElement for cloned attributes
Posted by Sebastien Ponce <se...@cern.ch>.
> True that I'm not using the latest one but xerces1.2. The reason is that I
> cannot compile xerces 1.3, some files are missing in
> org.apache.xerces.validators.schema.identity.
That's ok, I did a checkout instead of an update and I got it.
> You're right that the modification has been done in 1.3. I will try to make it
> compile and use it.
works fine.
Sebastien
Re: getOwnerElement for cloned attributes
Posted by Sebastien Ponce <se...@cern.ch>.
Arnaud Le Hors wrote:
> Sebastien Ponce wrote:
> >
> > It seems that a problem appears when cloning an element containing
> > attributes. The element an attributes themselves are correctly cloned but
> > the resulting attributes return null when calling getOwnerElement, instead
> > of the new element.
>
> Which version of Xerces are you using? I can't reproduce the problem
> with the latest. I just wrote a small test which seems to say this
> operation works just fine...
True that I'm not using the latest one but xerces1.2. The reason is that I
cannot compile xerces 1.3, some files are missing in
org.apache.xerces.validators.schema.identity.
You're right that the modification has been done in 1.3. I will try to make it
compile and use it.
Thanks a lot.
Sebastien
Re: getOwnerElement for cloned attributes
Posted by Arnaud Le Hors <le...@us.ibm.com>.
Sebastien Ponce wrote:
>
> It seems that a problem appears when cloning an element containing
> attributes. The element an attributes themselves are correctly cloned but
> the resulting attributes return null when calling getOwnerElement, instead
> of the new element.
Which version of Xerces are you using? I can't reproduce the problem
with the latest. I just wrote a small test which seems to say this
operation works just fine...
> This is due to the fact that the implementation of the cloneNode takes care
> to mark cloned attributes as "not owned" since a newly cloned attribute has
> nothing to do with the owner of its model. This is ok but while cloning an
> element, one should take care to mark every attribute as "owned" back and
> puting their owner to the new element.
> This has to be done in org.apache.xerces.dom.ElementImpl.cloneNode(). I
> would thus add there something like :
>
> NamedNodeMap nodemap = getAttributes();
> for (int i = 0; i < nodemap.getLength(); i++) {
> NodeImpl attr = (NodeImpl)nodemap.item(i);
> attr.isOwned(true);
> attr.ownerNode = this;
> }
>
> Could one commiter take care of that ?
This is actually what's done when the map is cloned. Here is the
relevant pieces of code:
ElementImpl:
public Node cloneNode(boolean deep) {
ElementImpl newnode = (ElementImpl) super.cloneNode(deep);
// Replicate NamedNodeMap rather than sharing it.
if (attributes != null) {
newnode.attributes = (AttributeMap)
attributes.cloneMap(newnode);
}
return newnode;
} // cloneNode(boolean):Node
NamedNodeMap:
protected NamedNodeMapImpl(NodeImpl ownerNode) {
this.ownerNode = ownerNode;
}
AttributeMap:
/** Constructs a named node map. */
protected AttributeMap(ElementImpl ownerNode, NamedNodeMapImpl
defaults) {
super(ownerNode);
if (defaults != null) {
// initialize map with the defaults
cloneContent(defaults);
if (nodes != null) {
hasDefaults(true);
}
}
}
public NamedNodeMapImpl cloneMap(NodeImpl ownerNode) {
AttributeMap newmap =
new AttributeMap((ElementImpl) ownerNode, null);
newmap.hasDefaults(hasDefaults());
newmap.cloneContent(this);
return newmap;
} // cloneMap():AttributeMap
/**
* Override parent's method to set the ownerNode correctly
*/
protected void cloneContent(NamedNodeMapImpl srcmap) {
if (srcmap.nodes != null) {
nodes = new Vector(srcmap.nodes.size());
for (int i = 0; i < srcmap.nodes.size(); ++i) {
NodeImpl n = (NodeImpl) srcmap.nodes.elementAt(i);
NodeImpl clone = (NodeImpl) n.cloneNode(true);
clone.isSpecified(n.isSpecified());
nodes.insertElementAt(clone, i);
clone.ownerNode = ownerNode;
clone.isOwned(true);
}
}
} // cloneContent():AttributeMap
--
Arnaud Le Hors - IBM Cupertino, XML Strategy Group
getOwnerElement for cloned attributes
Posted by Sebastien Ponce <se...@cern.ch>.
It seems that a problem appears when cloning an element containing
attributes. The element an attributes themselves are correctly cloned but
the resulting attributes return null when calling getOwnerElement, instead
of the new element.
This is due to the fact that the implementation of the cloneNode takes care
to mark cloned attributes as "not owned" since a newly cloned attribute has
nothing to do with the owner of its model. This is ok but while cloning an
element, one should take care to mark every attribute as "owned" back and
puting their owner to the new element.
This has to be done in org.apache.xerces.dom.ElementImpl.cloneNode(). I
would thus add there something like :
NamedNodeMap nodemap = getAttributes();
for (int i = 0; i < nodemap.getLength(); i++) {
NodeImpl attr = (NodeImpl)nodemap.item(i);
attr.isOwned(true);
attr.ownerNode = this;
}
Could one commiter take care of that ?
Thanks
Sebastien