473,791 Members | 3,111 Online
Bytes | Software Development & Data Engineering Community
+ 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 InternetExplore r , 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
programmaticall y using C#. I was trying to use XmlDocument and
XmlValidatingRe ader 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.x ml">] >
<root>
<element1>thi s is element 1</element1>
&inclX;
</root>

Example of "fragment.x ml" content:
<element2>thi s is element 1</element2>
<element3>thi s is element 1</element3>
Nov 12 '05 #1
2 14599


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
programmaticall y using C#. I was trying to use XmlDocument and
XmlValidatingRe ader 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 XmlValidatingRe ader 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" );
XmlValidatingRe ader xr = new XmlValidatingRe ader( xtr );
xr.EntityHandli ng = EntityHandling. ExpandEntities;
xr.ValidationTy pe = ValidationType. None;
while ( xr.Read() )
{
if ( xr.NodeType == XmlNodeType.Tex t )
{
Console.WriteLi ne( xmlReader.Value );
}
}

"Mark" <no****@nowhere .com> wrote in message
news:eV******** ******@TK2MSFTN GP10.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 InternetExplore r , 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
programmaticall y using C#. I was trying to use XmlDocument and
XmlValidatingRe ader 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.x ml">] >
<root>
<element1>thi s is element 1</element1>
&inclX;
</root>

Example of "fragment.x ml" content:
<element2>thi s is element 1</element2>
<element3>thi s 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
4380
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 multiple clubs. I would like to add support for letting each club define and store custom information about arbitrary entities. Basically, allows the clubs to define custom entities (i.e tables) and associated custom attributes (i.e. fields) that may be...
4
2502
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 the subject of entities. I did the following ---- top of file ---- <?xml version="1.0"?> <!-- I added this to an existing document. --> <!DOCTYPE observation-set >
2
5985
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: undefined entity: line 12, column 1 Does anyone know how to add entities when using xml.minidom? I've spend some time searching the docs/code/google but I haven't found the answer to this question!
1
1936
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 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...
0
1690
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 allowance When the book issued to the student i want the quantity to be reducted from the system for book entered.Students are given P2000.00 for book allowance,i want the system to be like this,when entering the book price to reduct the amount...
4
3220
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 appreciate if you could give a parser that can return all the Entities and Attributes of respective entities as an array. For e.g.: <?xml version="1.0" ?>
3
2070
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
2578
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.
2
4885
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 into web page n it shows special charactor easily. Here is the function code function charset_decode_utf_8($string) { /* Only do the slow convert if there are 8-bit characters */ /* avoid using 0xA0 (\240) in ereg ranges. RH73 does not...
0
10428
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...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10156
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
9997
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
9030
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5435
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...
1
4110
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
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.