473,387 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to read xml with entities ?

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 17 '05 #1
1 1908
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:%2****************@tk2msftngp13.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 17 '05 #2

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...
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:...
2
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...
1
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...
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...
6
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...
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...
1
Dormilich
by: Dormilich | last post by:
Hi, I got a strange behaviour (FF 3) of entities in my xml files. I have an element (see xml listing), where the attribute/content contains a latin1 entity (&ouml;), but FF throws an error...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.