473,386 Members | 1,812 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,386 software developers and data experts.

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 14557


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
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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,...

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.