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="&myextent;"/>
</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="&myextent;"/>
-------------------------------------------------
Thanks for your help,
Douglas 11 2278 do***********@yahoo.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="&myextent;"/> </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 "onewordwithoutCR">
--------------------------------------------------------
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
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.name> wrote in message news:<m3************@localhost.localdomain>... do***********@yahoo.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="&myextent;"/> </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 "onewordwithoutCR"> --------------------------------------------------------
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
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="&myintent;"/>
</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="&myintent;"/>
</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!
In article <m3************@localhost.localdomain>,
Micah Cowan <mi***@cowan.name> 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!
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.name> wrote in message news:<m3************@localhost.localdomain>... do***********@yahoo.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="&myextent;"/> </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 "onewordwithoutCR"> --------------------------------------------------------
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
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.name> wrote in message news:<m3************@localhost.localdomain>... do***********@yahoo.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="&myextent;"/> </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 "onewordwithoutCR"> --------------------------------------------------------
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
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!
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.txt">
<!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!
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.google.c om... 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="&myextent;"/> </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="&myextent;"/> -------------------------------------------------
Thanks for your help, Douglas
Bob, Richard,
Thanks for the assistance.
Just FYI:
The parser that allowed me to 'double' reference was Internet
Explorer, but I was only using it to test the XML validity and it
won't be the final parser. Hmmm, it now seems obvious that using
Internet Explorer as a benchmark was naive to say the least!
However I have a feeling I achieved a similar thing in the Perl
XML::Parser module. This would need to be retested.
I have not yet implemented the alternate solutions but will take a
look tomorrrow.
Thanks again,
Doug
"Bob Foster" <bo********@comcast.net> wrote in message news:<Gl********************@rwcrnsc52.ops.asp.att .net>... 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.google.c om... 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="&myextent;"/> </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="&myextent;"/> -------------------------------------------------
Thanks for your help, Douglas ri*****@cogsci.ed.ac.uk (Richard Tobin) writes: In article <m3************@localhost.localdomain>, Micah Cowan <mi***@cowan.name> wrote:
<!ENTITY myextent SYSTEM "./myextent.txt"> &myextent;
That needs to be a parameter entity:
<!ENTITY % myextent SYSTEM "./myextent.txt"> %myextent;
No it doesn't, but I agree that it might be slightly better.
-Micah This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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:
...
|
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"...
|
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...
|
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/>...
|
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...
|
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...
|
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>
|
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...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
| |