wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes about references to unparsed entities Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "about references to unparsed entities" Watch "about references to unparsed entities" New topic
Author

about references to unparsed entities

jim yin
Ranch Hand

Joined: Aug 15, 2002
Posts: 111
Hi, I am not very clear about the following statement:

Any reference to an unparsed entity would cause fatal XML parser errors.

Could anyone give an example about this? Thanks.
[ September 03, 2002: Message edited by: jim yin ]
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
I'm afraid it should be:
Any reference to an unresolved entity would cause fatal XML parsing errors.
For example, <root>&myentityreference;</root>, if it is not defined in DOCTYPE, then it would cause fatal parsing error. Easy to see, write a one line XML, then try to open it in IE.
[ September 01, 2002: Message edited by: Roseanne Zhang ]
jim yin
Ranch Hand

Joined: Aug 15, 2002
Posts: 111
Thanks Roseanne.
The above quote is from Professional XML p168.
And the following is the definition of unparsed entity:

non-XML data (can even be non-text data). All unparsed entities must have an associated notation, which is also identified by name. Unparsed entities are always external entities.

All these entity defitions are extremely confusing. It will cause a fatal error because an unparsed entity does not have an associated natation?
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
To add to your confusion, read more from here
W3: Extensible Markup Language (XML) 1.0 (Second Edition)
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Hi Jim,
Here are the following two statements you were enquiring about -
1) Any reference to an unparsed entity would cause fatal XML parser errors.
2) non-XML data (can even be non-text data). All unparsed entities must have an associated notation, which is also identified by name. Unparsed entities are always external entities.
============================================
Explanation for point (2)
Consider the scenario wherein we are using an xml document for the GUI layout of an application. When the user clicks on a "sound icon", say, we need to get the music file(song.mp3) and play it for the user. For this we need to know the application that plays the sound file (mp3Player i.e., mp3.exe).
The xml validator should not make an attempt to parse the external entity (which is the sound file song.mp3 in our case). The NDATA keyword used for defining the entity tells the parser that this is an unparsed enternal entity (hence don't try to parse it). The application that is making use of this xml document will know where to get the song and how to play it from the ENTITY declaration as given below. Rest of the things are intuitive here -
<!-- mp3Player is the notation's name -->
<!NOTATION mp3Player SYSTEM "http://www.zzz.com/mp3.exe">
<!-- Entity soundFile is the external unparsed -->
<!-- entity used along with the NDATA keyword -->
<!ENTITY soundFile SYSTEM "http://www.hostingservice.com/song.mp3" NDATA "mp3Player">
<!ATTLIST soundElement soundAttr ENTITY #REQUIRED>
The soundElement in our xml document looks something like below -
<soundElement soundAttr="soundFile"/>
===============================================
I think the first statement
"Any reference to an unparsed entity would cause fatal XML parser errors."
means that if we declare an external unparsed entity with the NDATA keyword, say, that would be a fatal error as shown below -
<!ENTITY imageFile SYSTEM "http://www.aa.com/bb.gif">
If i try to make an entity reference like
<someElement>
&imageFile;
</someElemet>
Though the above is syntatically(xml) well-formed, we are referring to an external unparsed entity and the resulting xml document will be invalid.
Anyone please correct me for any mistakes;
jim yin
Ranch Hand

Joined: Aug 15, 2002
Posts: 111
Thanks, Jayadev:
Your explanations make my doubts clearer. Do you mean the following?

means that if we declare an external unparsed entity without the NDATA keyword, say, that would be a fatal error as shown below -

Yes, I think so. NDATA will signal to validating processor that external entities will not be parsed.
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Jim,
sorry for missing out the "without" for the NDATA stuff; I mean it;
Also, i tried the following just a few moments back -
<!ENTITY imageFile SYSTEM "demo.gif">
without the NDATA keyword; When it run the xml document thru the validator, it tried to read the demo.gif (placed by me in the local directory) and complained about its contents ; Then when i changed it as below -
<!NOTATION img SYSTEM "imageViewer">
<!ENTITY imageFile SYSTEM "demo.gif" NDATA img>
it went fine thru the validator; This endorses the relevance of the NDATA keyword for the external unparsed entities;
Please let me know if you have any doubts; I'm also learning a lot of things in the process;
Thanks
 
Consider Paul's rocket mass heater.
 
subject: about references to unparsed entities
 
Similar Threads
Using XMLStreamReader to return actual XML strings of children?
JavaRanch XML mock exam errata-2
Does stylsheet(xsl) can take/pass session information?
Mock Test Questions
Is Lift a Scala framework like Play?