Help for parsing Internal ENTITY & Co

M

Max

I am writing a XML parser in Javascript and i have difficulty to understand
the specifics of some "entities". I would want to understand the way in
which the non-validating XML Parsers manage entities (ENTITY) in XML
documents.
In practical i don't understand if XML Parsers manage the values of Internal
Entities (<!ENTITY entityname "replacement text">), if they manage the
Parametric Entities and if the Entity Reference is only a Node or it is
linked to other Entities (Internal Entities).
I have given a look to many parser, written in many languages, but they make
more non-standard operations on the Internal Entity :-/
Can anyone help me?

Max
 
J

Joe Kesselman

The answer is "It depends".

Parsed entities may simply be expanded during parsing, in which case you
see only their replacement value as if that had been typed directly into
the file.

Or they may be separated out -- in the DOM, that's done by enclosing the
replacement value in an EntityReference node; SAX surrounds the
replacement value with calls to the LexicalHandler methods startEntity
and endEntity.

Which happens depends on which parser you're using, how you've
configured it, and what DOM implementation or SAX listeners these are
feeding.
 
M

Max

The answer is "It depends".
Parsed entities may simply be expanded during parsing, in which case you
see only their replacement value as if that had been typed directly into
the file.

Thanks for the response, Joe.

In practical, you think that the XML Parsers expands the entity references
while traversing the tree:

ex. in the internal DTD:
<!ENTITY name "Jerry">

XML file:

<hello>
<Cherries>&name;</Cherries>
</hello> Results:
<hello>
<Cherries>Jerry</Cherries>
Or they may be separated out -- in the DOM, that's done by enclosing the
replacement value in an EntityReference node; SAX surrounds the
replacement value with calls to the LexicalHandler methods startEntity
and endEntity.

In this case, is the replacement value enclosed in the nodeValue of
EntityReference Node (inherited by superclass Node) or in the nodeValue of
Entity Node or other?
Which happens depends on which parser you're using, how you've
configured it, and what DOM implementation or SAX listeners these are
feeding.

I'm writing a personal XML Parser.

All the best,

Max
 
J

Joe Kesselman

Or they may be separated out -- in the DOM, that's done by enclosing the
In this case, is the replacement value enclosed in the nodeValue of
EntityReference Node (inherited by superclass Node) or in the nodeValue of
Entity Node or other?

Children of the EntityReference node. See the DOM spec for details.
I'm writing a personal XML Parser.

If you really insist on doing this, I recommend you start by reading the
Annotated XML Specification website with extreme attention to every word
of the spec and of Tim Bray's commentary upon it. That'll save you from
having to repeat some of the mistakes everyone else has already made and
corrected.

Have fun.
 
M

Max

In this case, is the replacement value enclosed in the nodeValue of
Children of the EntityReference node. See the DOM spec for details.

During the parsing, i have to "map" the internal Entities and to add a
children node of matched type of internal value to EntityReference. If the
internal value is a element or another EntityReference, i have to re-parse
or re-expand it.
Is it correct?
If you really insist on doing this, I recommend you start by reading the
Annotated XML Specification website with extreme attention to every word
of the spec and of Tim Bray's commentary upon it. That'll save you from
having to repeat some of the mistakes everyone else has already made and
corrected.

Thanks for the suggests!

Max
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top