Re: [xml] Substitution of nested entity references
- From: Daniel Veillard <veillard redhat com>
- To: "Henke, Markus" <Markus_Henke ordat com>
- Cc: "'xml gnome org'" <xml gnome org>
- Subject: Re: [xml] Substitution of nested entity references
- Date: Wed, 10 Apr 2002 12:03:16 -0400
On Wed, Apr 10, 2002 at 05:24:25PM +0200, Henke, Markus wrote:
Maybe i've expressed myself unclear. The already built tree contains
XML_ENTITY_REF_NODEs as part of content of element nodes or attribute
values. As above mentioned, e.g. a call to xmlGetProp() on such an
attribute
(e.g. <aElement aAttr="Text &i_contain_an_entity_ref; MoreText" />)
results in something like
value = "Text &i_am_a_nested_entity_ref; MoreText"
which isn't the expected result.
xmlGetProp() does
ret = xmlNodeListGetString(node->doc, prop->children, 1);
i.e. with inLine=1
the loop in that function does:
------------------
} else if (node->type == XML_ENTITY_REF_NODE) {
if (inLine) {
ent = xmlGetDocEntity(doc, node->name);
if (ent != NULL)
ret = xmlStrcat(ret, ent->content);
else {
ret = xmlStrcat(ret, node->content);
}
} else {
xmlChar buf[2];
buf[0] = '&'; buf[1] = 0;
ret = xmlStrncat(ret, buf, 1);
ret = xmlStrcat(ret, node->name);
buf[0] = ';'; buf[1] = 0;
ret = xmlStrncat(ret, buf, 1);
}
}
------------------
So it should *not* return a value = "Text &i_am_a_nested_entity_ref; MoreText"
value ! And a simple script check confirms this:
paphio:~/XML -> python
Python 1.5.2 (#1, Jul 5 2001, 03:02:19) [GCC 2.96 20000731 (Red Hat Linux 7.1 2 on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
import libxml2
doc = libxml2.parseFile("tst.xml")
root = doc.getRootElement()
print root.prop("aAttr")
Text content MoreText
So why are you trying to remove them. No really I can't understand.
I wouldn't too, but i don't try to do so.
I want to accumulate the (useful) content of the different node
types (as child nodes of an entity declaration) with regard to the
case where the child node again is an entity reference (and do a
recursive call to xmlResolveEntityRef() in that case).
It's all about to enable routines like xmlGetProp(),
xmlNodeGetContent(), ... to result in a *complete* substitution
of an entity reference.
Okay, so you're just gathering content of the subtree. It seems to
me that xmlNodeGetContent() does just this. the only change which may
be needed is to change the handling of XML_ENTITY_REF_NODE nodes to recurse
in the node->children when the node found is such an entity ref.
Daniel
--
Daniel Veillard | Red Hat Network https://rhn.redhat.com/
veillard redhat com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]