![]() |
|
|
|||||||
![]() |
XML - Help for parsing Internal ENTITY & Co |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 Max |
|
|
|
|
#2 |
|
Posts: n/a
|
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. -- () ASCII Ribbon Campaign | Joe Kesselman /\ Stamp out HTML e-mail! | System architexture and kinetic poetry |
|
|
|
#3 |
|
Posts: n/a
|
> 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> </hello> > 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 |
|
|
|
#4 |
|
Posts: n/a
|
>>Or they may be separated out -- in the DOM, that's done by enclosing the
>>replacement value in an EntityReference node > > 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. |
|
|
|
#5 |
|
Posts: n/a
|
> > 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. 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 |
|