473,473 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to read XML with entities using C#

Hi there,
I have two xml files, one is a master file and the other is just a fragment
of xml. Master xml file uses 'DOCTYPE' to define the other file as an
entity. Then, the master uses entity references that are supposed to be
expanded into real content at parsing time. Examples are provided below.
When I open master xml file in InternetExplorer , IE shows correct content.
All the entities are transformed into right xml. So far I have been
unsuccessfull in getting similar result when I try to do the same
programmatically using C#. I was trying to use XmlDocument and
XmlValidatingReader but I am getting exceptions at the moment when I expect
entity reference to be transformed into correct content.

Is there a generic way [in C#] of expanding all the entities into real
content so when I read my xml I can get the content, not exceptions. Is it
possible at all ? If so, could anyone point me to an example that deals
with this issue ?

Thank you,
Mark.

Example of master file:
<!DOCTYPE inclusion [<!ENTITY inclX SYSTEM "fragment.xml">] >
<root>
<element1>this is element 1</element1>
&inclX;
</root>

Example of "fragment.xml" content:
<element2>this is element 1</element2>
<element3>this is element 1</element3>
Nov 12 '05 #1
2 14566


Mark wrote:

All the entities are transformed into right xml. So far I have been
unsuccessfull in getting similar result when I try to do the same
programmatically using C#. I was trying to use XmlDocument and
XmlValidatingReader but I am getting exceptions at the moment when I expect
entity reference to be transformed into correct content.


For XmlDocument you need to set the XmlResolver property in your code.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
I think I have just resolved the problem. Apparently the XML file was not
well formed and that is why XmlValidatingReader was blowing with exception.
I apologize for posting the question without applying enough testing first.
Mark

For those who are interested, here is the example that parses perfectly my
xml files:

XmlTextReader xtr = new XmlTextReader(@"d:\temp\master.xml" );
XmlValidatingReader xr = new XmlValidatingReader( xtr );
xr.EntityHandling = EntityHandling.ExpandEntities;
xr.ValidationType = ValidationType.None;
while ( xr.Read() )
{
if ( xr.NodeType == XmlNodeType.Text )
{
Console.WriteLine( xmlReader.Value );
}
}

"Mark" <no****@nowhere.com> wrote in message
news:eV**************@TK2MSFTNGP10.phx.gbl...
Hi there,
I have two xml files, one is a master file and the other is just a
fragment of xml. Master xml file uses 'DOCTYPE' to define the other file
as an entity. Then, the master uses entity references that are supposed
to be expanded into real content at parsing time. Examples are provided
below. When I open master xml file in InternetExplorer , IE shows correct
content. All the entities are transformed into right xml. So far I have
been unsuccessfull in getting similar result when I try to do the same
programmatically using C#. I was trying to use XmlDocument and
XmlValidatingReader but I am getting exceptions at the moment when I
expect entity reference to be transformed into correct content.

Is there a generic way [in C#] of expanding all the entities into real
content so when I read my xml I can get the content, not exceptions. Is it
possible at all ? If so, could anyone point me to an example that deals
with this issue ?

Thank you,
Mark.

Example of master file:
<!DOCTYPE inclusion [<!ENTITY inclX SYSTEM "fragment.xml">] >
<root>
<element1>this is element 1</element1>
&inclX;
</root>

Example of "fragment.xml" content:
<element2>this is element 1</element2>
<element3>this is element 1</element3>

Nov 12 '05 #3

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

Similar topics

3
by: Kunle Odutola | last post by:
I have a database that tracks players for children's sports clubs. I have included representative DDL for this database at the end of this post. A single instance of this database supports...
4
by: Peter C. Chapin | last post by:
I have a need to include Greek letters in some of my XML documents (the documents contain astronomical information and many stars are named using Greek letters). Following some earlier postings on...
2
by: Nick Craig-Wood | last post by:
I'm using xml.minidom to parse some of our XML files. Some of these have entities like "&deg;" in which aren't understood by xml.minidom. These give this error. xml.parsers.expat.ExpatError:...
1
by: Mark | last post by:
Hi there, I have two xml files, one is a master file and the other is just a fragment of xml. Master xml file uses 'DOCTYPE' to define the other file as an entity. Then, the master uses entity...
0
by: lletsweletse | last post by:
I have books and i have enter them into my database using microsoft access. Entities are:Vendor,Book Title,Quantity and price Student entities:Name,Book title,Book price,Quantity issued,Total...
4
by: ChillyRoll | last post by:
Hello guys, I am looking for a parser in PHP that can return all the attributes of XML entities. I know how to read the XML Entities, but I have got a problem with reading attributes. So I will...
3
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....
7
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...
2
by: neovantage | last post by:
hey geeks, I am using a function which convert unicode to entities. So that i can save values into mysql database into entities. This function really helps me when i display the store entity data...
0
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,...
0
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,...
0
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...
1
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...
0
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,...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.