473,804 Members | 3,789 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

About DTD Entities

I have a few questions about DTD ENTITY. I would appreciate any help.
1. Is there any equivalent of this in xsd? Suppose I want to use the
same string in multiple places in an xml file, is it possible to do
without DTD entities?

e.g. Consider two elements like this which are present in my xml file.
<AddValue>value 1</AddValue>

<CheckValue>val ue1</CheckValue>

By defining <!ENTITY val "value1"> I can use

<AddValue>&val; </AddValue>
and <CheckValue>&va l;</CheckValue>.

This will make sure that I can change value1 to value2 in just one
place and the other references will pick it up.

But everyone says that DTD is outdated. So is there any other way to
achieve this in XML?

2. If I have a code like above in an XML file and I use
XmlDataDocument Doc = new XmlDataDocument ();
Doc.Load(file); //where file is the name of the xml file
All the entity references are correctly resolved.

However, if I have the xml document stored as a string and then I use

XmlDataDocument Doc = new XmlDataDocument ();
Doc.LoadXml(szX mlString); //where szXmlString is the string that
contains
//the xml text
the code throws an exception. Why is that? Is there a way around it?

Thanks in advance.
Nov 11 '05 #1
3 3258
bheem wrote:
I have a few questions about DTD ENTITY. I would appreciate any help.
1. Is there any equivalent of this in xsd? Suppose I want to use the
same string in multiple places in an xml file, is it possible to do
without DTD entities? Not really. You can keep using entities, XmlSchema doesn't pretend to
substitute DTD at this point, instead Schema is fully focused on the
content model definition.
2. If I have a code like above in an XML file and I use
XmlDataDocument Doc = new XmlDataDocument ();
Doc.Load(file); //where file is the name of the xml file
All the entity references are correctly resolved.

However, if I have the xml document stored as a string and then I use

XmlDataDocument Doc = new XmlDataDocument ();
Doc.LoadXml(szX mlString); //where szXmlString is the string that
contains
//the xml text
the code throws an exception. Why is that? Is there a way around it?

Which exception are you talking about? Show us small reproducible sample
of such XML.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
Oleg Tkachenko <oleg@NO_SPAM_P LEASEtkachenko. com> wrote in message news:<O4******* *******@tk2msft ngp13.phx.gbl>. ..
Which exception are you talking about? Show us small reproducible sample
of such XML.
Thanks for your reply. Here is a simple sample.

string xmlText;
XmlDataDocument Doc = null;
xmlText = "<?xml version=\"1.0\" encoding=\"utf-8\"?> " +
"<!DOCTYPE TestScript[" +
"<!ENTITY ab \"1000\">" +
"]>" +
"<Root>&ab; </Root>";
Doc = new XmlDataDocument ();
Console.WriteLi ne("{0}", xmlText);
Doc.LoadXml(xml Text);

Essentially I am trying to load the following xml script
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TestScript[
<!ENTITY ab "1000">

<Root>&ab;</Root>

If I put the same script in a file and use Doc.Load(file) then it
works fine but the one above throws an exception like this

Unhandled Exception: System.NotSuppo rtedException: Cannot create
entity referenc
es on DataDocument.
at System.Xml.XmlD ataDocument.Cre ateEntityRefere nce(String name)
at System.Xml.XmlL oader.LoadEntit yReferenceNode( )
at System.Xml.XmlL oader.LoadCurre ntNode()
at System.Xml.XmlL oader.LoadChild ren(XmlNode parent)
at System.Xml.XmlL oader.LoadEleme ntNode()
at System.Xml.XmlL oader.LoadCurre ntNode()
at System.Xml.XmlL oader.LoadDocSe quence(XmlDocum ent parentDoc)
at System.Xml.XmlL oader.Load(XmlD ocument doc, XmlReader reader,
Boolean prese
rveWhitespace)
at System.Xml.XmlD ocument.Load(Xm lReader reader)
at System.Xml.XmlD ataDocument.Loa d(XmlReader reader)
at System.Xml.XmlD ocument.LoadXml (String xml)
Nov 11 '05 #3
bheem wrote:
string xmlText;
XmlDataDocument Doc = null;
xmlText = "<?xml version=\"1.0\" encoding=\"utf-8\"?> " +
"<!DOCTYPE TestScript[" +
"<!ENTITY ab \"1000\">" +
"]>" +
"<Root>&ab; </Root>";
Doc = new XmlDataDocument ();
Console.WriteLi ne("{0}", xmlText);
Doc.LoadXml(xml Text);

Essentially I am trying to load the following xml script
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TestScript[
<!ENTITY ab "1000">

<Root>&ab;</Root>

If I put the same script in a file and use Doc.Load(file) then it
works fine but the one above throws an exception like this


Now I see. You have to read such XML through XmlValidatingRe ader then to
be able to control all aspects of entiries resolving, e.g.:

string xmlText;
XmlDataDocument Doc = null;
xmlText = "<?xml version=\"1.0\" encoding=\"utf-8\"?> " +
"<!DOCTYPE TestScript[" +
"<!ENTITY ab \"1000\">" +
"]>" +
"<Root>&ab; </Root>";
Doc = new XmlDataDocument ();
Console.WriteLi ne("{0}", xmlText);
XmlTextReader r = new XmlTextReader(n ew StringReader(xm lText));
XmlValidatingRe ader vr = new XmlValidatingRe ader(r);
vr.ValidationTy pe = ValidationType. None;
Doc.Load(vr);

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #4

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

Similar topics

1
1265
by: sylvain.loiseau | last post by:
It's not so clear for me, in the xml spec, which is the required behaviour of an XML processor for entities : - The characters entities (predefined, decimal and hexadecimal) must be expended and treated as characters content ("Numeric character references MAY also be used; they are expanded immediately when recognized and MUST be treated as character data") - but what for the other entities (excluding parameters and unparsed entities...
3
2572
by: Michel de Becdeličvre | last post by:
I have some *performance* trouble reading MathML files in my application (in ASP.Net). - I have small MathML files (2-3k) as input - as (almost) all MathML files these use entities. I have no way to restrict the entities used. - to read an XML file entities into a document, you need to use a DTD, or you get an exception (any other way ?) - The MathML DTD is HUGE (2400+ Entities, ~300k of files), loading it in a document is a big CPU...
11
3190
by: Arsen Vladimirskiy | last post by:
Hello, If I have a few simple classes to represent Entities such as Customers and Orders. What is the proper way to pass information to the Data Access Layer? 1) Pass the actual ENTITY to the Data Access Layer method -or- 2) Pass some kind of a unique id to the Data Access Layer method
10
2269
by: sp | last post by:
I create an xml file in a text editor: <?xml version="1.0" encoding="utf-8"?> <elts> <elt id="1" class="c1">content1</elt> <elt id="2" class="c1">content2</elt> </elts> Then I load the file via xmlHttpRequest into xmlData variable. Why does xmlData.getElementById('1') return null and xmlData.firstChild.childNodes.className returns null also?
1
2021
by: David Bertoni | last post by:
Hi all, I'm trying to resolve what appears to me an inconsistency in the XML 1.0 recommendation involving entities encoding in UTF-16 and the requirement for a byte order mark. Section 4.3.3 has the following text: http://www.w3.org/TR/REC-xml/#charencoding
6
10170
by: clintonG | last post by:
Can anybody make sense of this crazy and inconsistent results? // IE7 Feed Reading View disabled displays this raw XML <?xml version="1.0" encoding="utf-8" ?> <!-- AT&T HTML entities & XML <elementsare displayed --> <rss version="2.0"> <channel> <title>AT&T HTML entities & XML <elementsare displayed</title> .... <description>
3
2074
by: bsagert | last post by:
Some web feeds use decimal character entities that seem to confuse Python (or me). For example, the string "doesn't" may be coded as "doesn’t" which should produce a right leaning apostrophe. Python hates decimal entities beyond 128 so it chokes unless you do something like string.encode('utf-8'). Even then, what should have been a right-leaning apostrophe ends up as "’". The following script does just that. Look for the string "The...
7
2580
by: tempest | last post by:
Hi all. This is a rather long posting but I have some questions concerning the usage of character entities in XML documents and PCI security compliance. The company I work for is using a third party ecommerce service for hosting its online store. A few months ago this third party commerce site began using PGP file encryption on XML files (e.g. web orders) transferred to us as part of the ongoing PCI security compliance.
22
3941
by: Luna Moon | last post by:
I am reading the book "C++ Annotations", and here is a quote from the book: Namespaces can be defined without a name. Such a namespace is anonymous and it restricts the visibility of the defined entities to the source file in which the anonymous namespace is defined. Entities defined in the anonymous namespace are comparable to C’s static functions and variables. In C++ the static keyword can still be used, but its use is more
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10577
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...
1
10320
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
10077
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
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.