Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newby problem: using !ENTITY

Status
Not open for further replies.

mashadt

Instructor
Apr 23, 2005
33
ZA
Hi - I have just begun learning XML and am flailing around a bit - apologies if this is a stupid question, but when you are a beginner, all questions are important...

I have been running into this problem with using entities. When I open the xml below in a browser (Firefox 1.0.2 or Mozilla 1.7.7)
I get an error message "XML Parsing Error: undefined entity".

When I look at it in the "browser view" of XML spy, it looks OK.

Can someone explain to me why this is?



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE contract [
<!ELEMENT contract (para1, para2)>
<!ELEMENT para1 (#PCDATA)>
<!ELEMENT para2 (#PCDATA)>
<!ATTLIST para2
section CDATA #REQUIRED >

<!ENTITY buyer "Masha du Toit">

]>
<contract>
<para1> &buyer; agrees to buy the property defined below

</para1>
<para2 section="1">&buyer; will take title of the real property if &buyer; agrees to this
</para2>
</contract>
 
Displays fine in IE and firefox v1.0.3

Jon

"There are 10 types of people in the world... those who understand binary and those who don't.
 
Hi JontyMC

What do you know. Just after I posted this question, I realised that I had not saved the changes to my xml document before checking it in the browser. Geuss no one is immune from stupid mistakes.

It works now.

Lets hope I have more serious problems in future :)

Thanks anyway

Masha
 
OK - Now I am stuck again and I cant see where my mistake is this time. I suspect it must be in the reference to the DTD.

I have changed the example above to an xml file with an external DTD, and now it does not work anymore.

The DTD looks like this



<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT contract (para1, para2)>
<!ELEMENT para1 (#PCDATA)>
<!ELEMENT para2 (#PCDATA)>
<!ATTLIST para2
section CDATA #REQUIRED
>
<!ENTITY buyer "Masha du Toit">


And the xml looks like this:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE contract SYSTEM "contract01.dtd">
<contract>
<para1> &buyer; agrees to buy the property defined below

</para1>
<para2 section="1">&buyer; will take title of the real property if &buyer; agrees to this
</para2>
</contract>



When I test that in my browser, (Firefox 1.0.2 or Mozilla 1.7.7)I get an error message "XML Parsing Error: undefined entity".

When I look at it in the "browser view" of XML spy, it looks OK. Any ideas where I am going wrong this time?
 
The code is fine and works in IE. The problem is that gecko based browsers do not load external dtd's. I'm not sure exactly why, but I'm sure you could google for the answer to that.

Jon

"There are 10 types of people in the world... those who understand binary and those who don't.
 
Well thats worth knowing!

Thanks again
Masha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top