[Expat-discuss] Bug? Illegal parameter reference error for valid document
Josh Martin
Josh.Martin@abq.sc.philips.com
Tue Nov 6 11:39:14 2001
Hi,
I was having alot of problems with nested external entities. I would assume
that your problem is the same as the problem that I was having. When you parse
your XML document and external entities you need to either read the file in one
byte at a time, or you need to read in one line at a time (stopping at the
newline character). The reason for this is that if you read past the newline
you might pick up more than one entity declaration in your buffer. After you
come back from you external entity handler you will start reading after the end
of the buffer and lose the extra information. This will most likely cause you
to miss some of the declarations. For example take the entity file "004-1.ent":
1: <!ELEMENT doc EMPTY>
2: <!ENTITY % e1 SYSTEM "004-2.ent">
3: <!ENTITY % e2 "%e1;"> --> Expat does not seem to like "%e1;"
4: %e1;
If you use a large buffer and just read in bytes until you fill the buffer and
then parse it, you will probably load the whole file into the buffer. When you
parse the buffer the external entity handler will be called on the second line
(which contains the 'e1' entity declaration). When you return from the external
entity parser and begin parsing again the parser will start at the end of the
file, skipping lines 3 and 4. If you parse the file either one byte at a time,
or one line at a time then all of the entity declarations will be parsed
correctly.
Also, make sure that you have something like the following in your main parser
loop, otherwise you might never parse all the entities that you need to parse.
XML_SetParamEntityParsing(p, XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE);
Personally I think this behavior of expat is flawed, since other handlers seem
to be called multiple times just fine if there are multiple instances in the
buffer. However, the fact that the external entity handler spawns off an
entirely new parser probably throws a monkey wrench into the whole deal.
Meanwhile you can just use the work-around that I mentioned and it should all
work just fine. Let me know if this fixes your problem, or if you find another
solution.
- Josh Martin
> From: "Karl Waclawek" <karl@waclawek.net>
> To: <expat-discuss@lists.sourceforge.net>
> Cc: <karl@waclawek.net>
> X-Original-Date: Mon, 5 Nov 2001 09:48:28 -0500
> Date: Mon, 5 Nov 2001 09:48:28 -0500
>
>
> I ran Expat 1.95.2 against James Clark's test cases version 1998-11-18.
> There are two files in the directory \valid\not-sa, which are supposed
> to be valid, but Expat returns an "illegal parameter entity reference"
> error. Is this a bug, or are the test cases outdated, or am I doing something
wrong?
>
> Here is how it looks for the first file:
>
> File 004.xml:
> <!DOCTYPE doc SYSTEM "004-1.ent">
> <doc></doc>
>
> File 004-1.ent:
> <!ELEMENT doc EMPTY>
> <!ENTITY % e1 SYSTEM "004-2.ent">
> <!ENTITY % e2 "%e1;"> --> Expat does not seem to like "%e1;"
> %e1;
>
> File 0004-2.ent:
> <!ATTLIST doc a1 CDATA "value">
>
> And the second file:
>
> File 003.xml:
> <!DOCTYPE doc SYSTEM "003-1.ent">
> <doc></doc>
>
> File 003-1.ent:
> <!ELEMENT doc EMPTY>
> <!ENTITY % e SYSTEM "003-2.ent">
> <!ATTLIST doc a1 CDATA %e; "v1"> --> Expat does not seem to like %e
>
> File 003-2.ent: empty file
>
> Is it possible that I am doing something wrong, maybe
> in calling the external entity reference handler?
>
> Karl
>
>
> _______________________________________________
> Expat-discuss mailing list
> Expat-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/expat-discuss