473,761 Members | 4,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

External Entity in Att Value: Why Forbidden?

Hi There,
Can someone please tell me why the XML spec states that an attribute
value with an external entity is forbidden? Or point me to the
appropriate document? Or better still, perhaps you know of a work
around?

It is a little frustrating that the normally powerful external
entities are limited in this fashion.

Example (myextent.txt contains just one word without a CR):
-------------------------------------------------
<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
]>
<mydoc>
<atag name="fred" value="&myexten t;"/>
</mydoc>
-------------------------------------------------

Error:
-------------------------------------------------
Cannot reference an external general parsed entity 'myextent' in an
attribute value. Error processing resource...
Line 6, Position 44
<atag name="fred" value="&myexten t;"/>
-------------------------------------------------

Thanks for your help,
Douglas
Jul 20 '05 #1
11 2392
do***********@y ahoo.com.au (Douglas Reith) writes:
Hi There,
Can someone please tell me why the XML spec states that an attribute
value with an external entity is forbidden? Or point me to the
appropriate document? Or better still, perhaps you know of a work
around?

It is a little frustrating that the normally powerful external
entities are limited in this fashion.

Example (myextent.txt contains just one word without a CR):
-------------------------------------------------
<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
]>
<mydoc>
<atag name="fred" value="&myexten t;"/>
</mydoc>
-------------------------------------------------


I can't really understand why you would want that. If you want
the value of value to be literally "./myextent.txt", then you
don't need SYSTEM in the <!ENTITY> declaration (and don't want
it). If you really want to be able to specify the value in the
content of an external document, then you could try:

-----(contents of your (modified) example:)-------------

<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
&myextent;
]>
<mydoc>
<atag name="fred" value="&myvalue ;"/>
</mydoc>
--------------------------------------------------------

-----(contents of myextent.txt)-------------------------
<!ENTITY myvalue "onewordwithout CR">
--------------------------------------------------------

Or, you could redesign <atag> (if you have such control) so that
&myextent; goes in the content, rather than an attribute.

If you're thinking, "that's not fair", recall that XML was never
designed to be able to import arbitrary text files directly as
content (after all, what if your one word contained an
ampersand?).

-Micah

Jul 20 '05 #2
Thanks Micah,
I can't really understand why you would want that. Users don't want to modify an XML document when configuring the
system, they prefer one word documents. It's a long story and I don't
agree with it but now we have the unenviable requirement.
the value of value to be literally "./myextent.txt" No we really need the contents of the file.
then you could try: I didn't think of this work around (thanks). I think it will be the
closest we can get to a solution.
Or, you could redesign <atag> (if you have such control) The DTD is directed by a third party, so no, we don't have control.
content (after all, what if your one word contained an
ampersand?). I'd argue that we'd just have to manage the error. That is, understand
the problem -> create the solution. You have extra flexibility and
extra risk which I think is fair. On another note, sometimes I use
ampersands in internal entities so that I can refer to entities within
entities!

Again, I'm unclear as to why there is a restiction.

Regards,
Douglas
Micah Cowan <mi***@cowan.na me> wrote in message news:<m3******* *****@localhost .localdomain>.. . do***********@y ahoo.com.au (Douglas Reith) writes:
Hi There,
Can someone please tell me why the XML spec states that an attribute
value with an external entity is forbidden? Or point me to the
appropriate document? Or better still, perhaps you know of a work
around?

It is a little frustrating that the normally powerful external
entities are limited in this fashion.

Example (myextent.txt contains just one word without a CR):
-------------------------------------------------
<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
]>
<mydoc>
<atag name="fred" value="&myexten t;"/>
</mydoc>
-------------------------------------------------


I can't really understand why you would want that. If you want
the value of value to be literally "./myextent.txt", then you
don't need SYSTEM in the <!ENTITY> declaration (and don't want
it). If you really want to be able to specify the value in the
content of an external document, then you could try:

-----(contents of your (modified) example:)-------------

<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
&myextent;
]>
<mydoc>
<atag name="fred" value="&myvalue ;"/>
</mydoc>
--------------------------------------------------------

-----(contents of myextent.txt)-------------------------
<!ENTITY myvalue "onewordwithout CR">
--------------------------------------------------------

Or, you could redesign <atag> (if you have such control) so that
&myextent; goes in the content, rather than an attribute.

If you're thinking, "that's not fair", recall that XML was never
designed to be able to import arbitrary text files directly as
content (after all, what if your one word contained an
ampersand?).

-Micah

Jul 20 '05 #3
In article <c2************ **************@ posting.google. com>,
Douglas Reith <do***********@ yahoo.com.au> wrote:
Can someone please tell me why the XML spec states that an attribute
value with an external entity is forbidden?
I think - though it takes ages to try and find any reference for this
sort of thing in the W3C archives - that the rationale is that:

- parsers don't have to expand external entity references, unlike
internal ones;
- attributes should be returnable as simple strings, which they
wouldn't be if they contained unexpanded (necessarily external)
entity references.

Unfortunately this explanation doesn't really work, since there may
be references to externally-declared internal entities, and parsers
may not know about them either.
Or better still, perhaps you know of a work around?


Yes, but it's a bit messy.

You could use an externally declared internal entity (i.e. instead of
putting just the text in an external entity, put an entity definition
in the external entity and make it a parameter entity).

Or - if you want to just have the replacement text in the file as you
do now - you could use the external entity as a parameter entity and
refer to it in the definition of an internal entity. Unfortunately
this doesn't quite work:
<!DOCTYPE mydoc [
<!ENTITY % myextent SYSTEM "./myextent.txt">
<!ENTITY myintent "%myextent; "> <!-- WRONG!!! -->
]>
<mydoc>
<atag name="fred" value="&myinten t;"/>
</mydoc>

because you can't use a parameter entity reference that way in the
internal subset, but if you put your declarations in an external
parameter entity it will work:

<!DOCTYPE mydoc [
<!ENTITY % mydecls SYSTEM "mydecls">
%mydecls;
]>
<mydoc>
<atag name="fred" value="&myinten t;"/>
</mydoc>

with this in mydecls:

<!ENTITY % myextent SYSTEM "./myextent.txt">
<!ENTITY myintent "%myextent; ">

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!
Jul 20 '05 #4
In article <m3************ @localhost.loca ldomain>,
Micah Cowan <mi***@cowan.na me> wrote:
<!ENTITY myextent SYSTEM "./myextent.txt">
&myextent;


That needs to be a parameter entity:

<!ENTITY % myextent SYSTEM "./myextent.txt">
%myextent;

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!
Jul 20 '05 #5
Actually Micah,
I might be doing something wrong but with your example I get this:

Invalid character found in DTD. Error processing resource
'file:///C:/Documents and Settings/user/Desktop/text.xml'. Line 3,
Position 4

&myextent;
---^

Perhaps it's not possible to use entities in the document prolog?

Douglas
Micah Cowan <mi***@cowan.na me> wrote in message news:<m3******* *****@localhost .localdomain>.. .
do***********@y ahoo.com.au (Douglas Reith) writes:
Hi There,
Can someone please tell me why the XML spec states that an attribute
value with an external entity is forbidden? Or point me to the
appropriate document? Or better still, perhaps you know of a work
around?

It is a little frustrating that the normally powerful external
entities are limited in this fashion.

Example (myextent.txt contains just one word without a CR):
-------------------------------------------------
<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
]>
<mydoc>
<atag name="fred" value="&myexten t;"/>
</mydoc>
-------------------------------------------------


I can't really understand why you would want that. If you want
the value of value to be literally "./myextent.txt", then you
don't need SYSTEM in the <!ENTITY> declaration (and don't want
it). If you really want to be able to specify the value in the
content of an external document, then you could try:

-----(contents of your (modified) example:)-------------

<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
&myextent;
]>
<mydoc>
<atag name="fred" value="&myvalue ;"/>
</mydoc>
--------------------------------------------------------

-----(contents of myextent.txt)-------------------------
<!ENTITY myvalue "onewordwithout CR">
--------------------------------------------------------

Or, you could redesign <atag> (if you have such control) so that
&myextent; goes in the content, rather than an attribute.

If you're thinking, "that's not fair", recall that XML was never
designed to be able to import arbitrary text files directly as
content (after all, what if your one word contained an
ampersand?).

-Micah

Jul 20 '05 #6
But..
I have managed to get this to work:

----------------------------------------------------
<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
<!ENTITY myvalue "&myextent; ">
]>
<mydoc>
<atag name="fred" value="&myvalue ;"/>
</mydoc>
-----------------------------------------------------

myextent.txt just contains the single word.

The parser has been tricked!
Douglas
Micah Cowan <mi***@cowan.na me> wrote in message news:<m3******* *****@localhost .localdomain>.. .
do***********@y ahoo.com.au (Douglas Reith) writes:
Hi There,
Can someone please tell me why the XML spec states that an attribute
value with an external entity is forbidden? Or point me to the
appropriate document? Or better still, perhaps you know of a work
around?

It is a little frustrating that the normally powerful external
entities are limited in this fashion.

Example (myextent.txt contains just one word without a CR):
-------------------------------------------------
<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
]>
<mydoc>
<atag name="fred" value="&myexten t;"/>
</mydoc>
-------------------------------------------------


I can't really understand why you would want that. If you want
the value of value to be literally "./myextent.txt", then you
don't need SYSTEM in the <!ENTITY> declaration (and don't want
it). If you really want to be able to specify the value in the
content of an external document, then you could try:

-----(contents of your (modified) example:)-------------

<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
&myextent;
]>
<mydoc>
<atag name="fred" value="&myvalue ;"/>
</mydoc>
--------------------------------------------------------

-----(contents of myextent.txt)-------------------------
<!ENTITY myvalue "onewordwithout CR">
--------------------------------------------------------

Or, you could redesign <atag> (if you have such control) so that
&myextent; goes in the content, rather than an attribute.

If you're thinking, "that's not fair", recall that XML was never
designed to be able to import arbitrary text files directly as
content (after all, what if your one word contained an
ampersand?).

-Micah

Jul 20 '05 #7
In article <c2************ **************@ posting.google. com>,
Douglas Reith <do***********@ yahoo.com.au> wrote:
<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
<!ENTITY myvalue "&myextent; ">
]>
<mydoc>
<atag name="fred" value="&myvalue ;"/>
</mydoc> The parser has been tricked!


That shouldn't work. If you switch to a different parser, or newer
version of the one you're using, it will quite likely stop working.

(The reference to myextent is *not* expanded when myvalue is defined,
it is "bypassed", and should cause an error when encountered during
attribute value processing.)

What parser accepted this?

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!
Jul 20 '05 #8
Here is a version of the above that does work. The entity must be replaced
by a parameter entity and the whole thing must be moved to an external DTD.
That's all.

--in mydoc.doc
<!DOCTYPE mydoc SYSTEM "mydtd.dtd" >
<mydoc>
<atag name="fred" value="&myvalue ;"/>
</mydoc>

--in mydtd.dtd
<!ELEMENT mydoc (atag)>
<!ELEMENT atag EMPTY>
<!ATTLIST atag
name CDATA #IMPLIED
value CDATA #IMPLIED
<!ENTITY % myextent SYSTEM "myextent.t xt">
<!ENTITY myvalue "%myextent; ">

--in myextent.txt
foo

The element and attlist declarations were needed to get the document to
validate. Otherwise, it's pretty much the same trick.

In light of this, the original question seems like a good one. What's the
point of disallowing a direct reference to an external entity in an
attribute when the reference can be easily made indirectly?

Bob Foster


"Richard Tobin" <ri*****@cogsci .ed.ac.uk> wrote in message
news:bl******** ***@pc-news.cogsci.ed. ac.uk... In article <c2************ **************@ posting.google. com>,
Douglas Reith <do***********@ yahoo.com.au> wrote:
<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
<!ENTITY myvalue "&myextent; ">
]>
<mydoc>
<atag name="fred" value="&myvalue ;"/>
</mydoc>
The parser has been tricked!


That shouldn't work. If you switch to a different parser, or newer
version of the one you're using, it will quite likely stop working.

(The reference to myextent is *not* expanded when myvalue is defined,
it is "bypassed", and should cause an error when encountered during
attribute value processing.)

What parser accepted this?

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the

headers.
FreeBSD rules!

Jul 20 '05 #9
In case it's not obvious, a workaround is in my reply to Richard Tobin.

Bob Foster

"Douglas Reith" <do***********@ yahoo.com.au> wrote in message
news:c2******** *************** ***@posting.goo gle.com...
Hi There,
Can someone please tell me why the XML spec states that an attribute
value with an external entity is forbidden? Or point me to the
appropriate document? Or better still, perhaps you know of a work
around?

It is a little frustrating that the normally powerful external
entities are limited in this fashion.

Example (myextent.txt contains just one word without a CR):
-------------------------------------------------
<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
]>
<mydoc>
<atag name="fred" value="&myexten t;"/>
</mydoc>
-------------------------------------------------

Error:
-------------------------------------------------
Cannot reference an external general parsed entity 'myextent' in an
attribute value. Error processing resource...
Line 6, Position 44
<atag name="fred" value="&myexten t;"/>
-------------------------------------------------

Thanks for your help,
Douglas

Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2031
by: ittay.dror | last post by:
Hi, I have a build.xml with the following header: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE project > When I launch ant, the jar that holds common.ent is in the classpath (by setting it in LOCALCLASSPATH variable). I get:
2
3527
by: David Dorward | last post by:
I'm attempting to read an XHTML 1.1 file, perform some DOM manipulation, then write the results to a different file. I've found myself rather stuck at the first hurdle. I have the following: from xml.dom.ext.reader import Sax2 reader = Sax2.Reader() f = open('dorward.me.uk/sitemap.html', 'r')
3
3332
by: Robert Lintner | last post by:
Hi, I woult like to switch from DTD to XML-Schema and am looking for an equivalent to external ENTITY for composition of an xml file from modules --- my.dtd -- <?xml version="1.0" encoding="ISO-8859-1"?> <!ENTITY module1 SYSTEM "module1.xml"> <!ENTITY module2 SYSTEM "module2.xml"> .....
1
2512
by: David Madore | last post by:
Hi! Anyone in for a Byzantine discussion on XML well-formedness? Here's the situation: test.xml contains --- test.xml: cut after --- <?xml version="1.0" encoding="us-ascii"?> <!DOCTYPE foobar > <foobar />
6
2060
by: Thomas Sommer | last post by:
Hi, I know doing something like this <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" > <section><title/> <programlisting><xi:include href="&test;" parse="text"
0
1456
by: Shawn Modersohn | last post by:
Can someone give me the lowdown on the way these two browsers deal with the following <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/css" href="datadump.css"?> <!DOCTYPE datadump > <datadump> <name> <first>&txt;</first> <last>&sig;</last>
1
6595
by: Razvan | last post by:
Hi What is the difference between an internal and an external entity ? The first one is defined in the internal subset (not in a separate DTD file, but in the XML file itself - in DOCTYPE) while the second one is defined in the external subset (in a separate DTD file) ? Or an
0
1140
by: Tom | last post by:
I need to modify a DocBook file with several other XML files included as an ENTITY reference. Like <!DOCTYPE book SYSTEM "PathToMyDTD" > <book> &file1; &file2; &file3; </book>
0
1352
by: punjabinezzie | last post by:
I am developing an Application which currently has two XML files. One XML file with some nodes and an external entity reference to another XML file. The source XML file is being parsed using Xerces (DOM Parser), upon reaching an external entity reference node the external file being referenced does not get parsed. Instead an empty node or the current node name is substituted in place and the remaining nodes parsed from original source file...
0
9522
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9948
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7327
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.