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>


0
nospam3434 (231)
7/13/2005 2:59:55 PM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
898 Views

Similar Articles

[PageSpeed] 12

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" <nospam@nowhere.com> wrote in message 
news:eV319v7hFHA.1372@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>
>
> 


0
nospam3434 (231)
7/13/2005 3:24:49 PM

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/
0
mahotrash (1778)
7/13/2005 3:25:02 PM
Reply:

Similar Artilces:

Use custom task form in Outlook 2003 when creating task in ON 2007
I have a custom task form in Outlook 2003 that I use for all of my task-related info. I rely heavily on this form, and would like to have it be the form that isused when ON creates a task (using any of the Outlook Task tags). Is it possible to do this? -- Bobby C Hi Bobby, You might get better help if you posted this in the Outlook Forum since this is an Access Forum. Happy New Year! Patrick Wood "Bobby C" wrote: > I have a custom task form in Outlook 2003 that I use for all of my > task-related info. I rely heavily on this form, and would like to have it be > ...

Reading .wks file
Greetings...according to the Excel "help" file, as well as the file extension listing, I *should* be able to read an *.wks file, but Excel insists that it cannot. I am pretty sure the file was created in Microsoft Works. Is there a converter somewhere that I can download/install? Cheers - S2 Excel can read Works 2.0, not later. You have to save them in Works as excel files or Works 2.0 or get a commercial converter. -- Regards, Peo Sjoblom "Skip Stocks" <anonymous@discussions.microsoft.com> wrote in message news:AFC110E0-641D-4D87-9464-B930CC41CF02@microsoft....

xml config file...
hello, I ve a Windowsapplication with a configuration file app.config... (it's in xml) code app.config: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name = "MyNameValueSection" type="System.Configuration.NameValueSectionHandler" /> </configSections> <MyNameValueSection> <add key="MyKey" value="MyValue" /> </MyNameValueSection> <appSettings> <add key="test" value="MeinInhalt" /> </appSettings> </configurati...

Updating links that use SUMIF #2
Thanks Peo. Works perfectly -- BHawle ----------------------------------------------------------------------- BHawley's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1546 View this thread: http://www.excelforum.com/showthread.php?threadid=27054 ...

File won't open as read only
I have a file that is in use, but another person opens it and it doeasn't display the "file is in use" message. Is there a setting or fix? Hi have you shared this file? -- Regards Frank Kabel Frankfurt, Germany John wrote: > I have a file that is in use, but another person opens it > and it doeasn't display the "file is in use" message. Is > there a setting or fix? The file is on a network share. The share has all the appropriate permissions. >-----Original Message----- >Hi >have you shared this file? > >-- >Regards >Frank Ka...

Binding ASP.NET Menu to XML
I have created a XmlDocument that contains the exact layout that siteMap uses, and then I bind my Menu object to it: Dim xml As XmlDocument xml = DirectCast(Session("MenuData"), XmlDocument) Dim xmlDS As New XmlDataSource() xmlDS.Data = xml.OuterXml MainMenu.DataSource = xmlDS Dim mb As New MenuItemBinding() mb.DataMember = "SiteMapNode" mb.TextField = "Title" mb.NavigateUrlField = "url" MainMenu.DataBindings.Add(mb) MainMenu.DataBind() The problem is when it dis...

How to give other users read-only access to Calendar
I want to allow the group Everyone to have read-only access to a calendar in a certain mailbox. I can do this by granting the permission 'Full mailbox access' (under 'Mailbox rights', under 'Exchange Advanced', for the particular user). However this also allows people to to do everything (ie: they become read-write users). I notice that every mailbox in the system has 'Read permissions' granted to group Everyone. This does not allow other people to open items in the mailbox, but as I understand it, permits Exchange Server and Outlook to do shared meetin...

Read mail arn't marked as read anymore
After an SP upgrade of my Office 2000 the priviewed mail doesnt get marked as read anymore. I have tried to change the time (Tools->Options->Priview pane) from 2 -> 3 -> 4 seconds but nothing works. The only way to mark a mail as read is either to open it or right click it and chose Mark as read. Since I only use the priview pane this is very anoying for me. Is this a bug or has some setting changed with the SP? ...

using list or combo boxes
Hello, I have a form with several fields: ID Number, LName, Fname, Employer, Employer1 Depts and Employer2 Depts. I want to enter data in first 3 fields (text) which will be inserted to table 1. I want to select a value from a lookup table for employer. Based on the Employer chosen, either Emp1 depts OR Emp2 depts drop down will become active. Finally, select a dept from the active dropdown. Am I thinking correctly in the following: For the OnChange event when the employer is selected from the dropdown, I want to do this: IF employer = EMP1 then 1.1 enable cboEMP1 ...

About: Using IHtmlElementRender to print HTML document?
I have realized the printing preview/output to printer in my project. but there is a problem, when the HTML document is larger than paper restriction, I need to do pagination with the document, How do I? I ever tried to use the 'Print-template' method which can be found from MSDN, but however I can't use the method, because I reform the behavior of IWebBrowser2 using asynchronously plug-in technic, to render html document on screen, some images and CSS file is read from memory, Thus, once I use 'Print-template' method that can't parse images and CSS, whole layout...

why can i not use outlook with aol
i have decided to use outlook with aol so use imap but it does not work all the settings seem to be correct so can anyone please help me In news:16B645A7-B411-4BEC-9D91-41DF7C7B8E38@microsoft.com, stevediggo <stevediggo@discussions.microsoft.com> had this to say: My reply is at the bottom of your sent message: > i have decided to use outlook with aol so use imap but it does not > work all the settings seem to be correct so can anyone please help me Perhaps this might be of assistance? Accessing the AOL Mail System using IMAP & Authenticated SMTP - An Unofficial Guide: ...

reading confirmation
Good day, I have a problem with outlook. When they send a message to me that demands the shipment of a reading confirmation, even if I accept, the reading confirmation does not come received from the sender. Someone knows from what depends and in which way I can resolve the problem? Thanks for the eventual answers. Niki In news:eht7fo$251$1@fata.cs.interbusiness.it, Niki <nicola.pantaleo@yahoo.it> typed: > Good day, > > I have a problem with outlook. When they send a message to me that > demands the shipment of a reading confirmation, even if I accept, the > read...

Using OWA on a PC without Outlook installed
I have a PC with W2K and Office 2000, but Outlook has been uninstalled on it. This PC needs to use OWA (Outlook Web Access) but every time I try to send an email or change my options up pops up a Windows install window trying to install some missing Windows components which I suspect to be Outlook. I find it hard to believe that a browser based email reading application requires that Outlook be installed on the PC so I am checking here to see what others have found out. Thanks, Hank ...

VS C++ 6.0 hanging problem in Windows XP ...
Hi, My VS C++ 6.0 has worked fine for 4 years. Recently I upgraded my os from 2000 to XP. Now my VS C++ 6.0 sometimes just hangs forever after I make a build command. From the output window I know it's linking. Nothing happens if I stop the building (ctrl-break). If I exit, it says that I have to stop building before exiting. Eventually I have to go to the task manager to kill the process. This situation takes place for any of my projects. Not always, but often enough to affect my work. Do you have any idea what is happening or is there any resolution? I have already rein...

Add blocked domain using right-click option
I know how to add a domain to my blocked e-mail list. But I would like to have the option to do this by right- clicking on the e-mail within Outlook. To the best of my knowledge, right-clicking on the e-mail only gives the option to add the entire e-mail address to my blocked senders list - but I would like to right-click and select "add domain to blocked senders list." Anyone know how to do this? It would be helpful if you could notify me at hemetz@cox.net when you find an answer. Thanks! Right now, it is not possible to add a domain address via the right click context me...

"Unblock" feature should be optional when reading e-mail in CRM
When viewing e-mail messages in CRM, a line appears saying "Unblock" to allow the full message content to be read. Can this be made a configurable server or security setting? We are trying to reduce "clicks" as much as possible. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agre...

Cannot delete xml file - file based event scheduling
Hi, I have a report scheduled with File based event scheduling in CR XI Server version 11.5. The report is created with XML file as its datasource. The report will be triggered if the event of xml file is created in the source directory. As per the schedule, it will look for the event to occur every 1 minute. Since I need to enerate this report everytime the file comes into the directory, I have to delete the file after he report is generated, so that, next time the file comes in, the report will be generated again. After the report is run for the first time successfuly as the event occurs...

Previously used file option GONE? help please
Win98SE 'Office XP Pro' In Excel I am unable to find how to enable "open previosly used files" or words to that effect. I have checked in "options" but cannot see it there. When I used it previouly I was able to select the number of files last used, which would be available for me to select when starting EXCEL. TIA Hi do you mean the option in the 'File' menu (at the bottom)? -- Regards Frank Kabel Frankfurt, Germany Terry wrote: > Win98SE > 'Office XP Pro' > > In Excel I am unable to find how to enable "open previosly used...

The memory could not be "read".
I'm at work yesterday afternoon responding to e-mail on my desktop, and Adobe pops up from the toolbar with a notice that there is an update available for Acrobat. I accept the download, keep plugging away at my e-mail, and install it when it's done. It runs through the install, tells me that I should restart, but I ignore it and keep working. It's near the end of the day and I'm going to be going home soon anyways. I forgot to turn it off when I left. Came in this morning, restarted it through the Start menu, and rebooted. Upon reaching the "Ctrl+Alt+Del" ...

Choose record info using ComboBox
I have tblProjects (Key = ProjectID) I made a form (record source = tblPtojects) containing all the fields form tblProjects I want the user to pick a project using a combobox, and have the other fields updated with the project's info, instead of navigating through projects using the form buttons. Currently, when I select a project in the combo, nothing happens. What do I need? Antonio. "AntonioMachado" <u35762@uwe> wrote in message news:7507769e3a4da@uwe... >I have tblProjects (Key = ProjectID) > > I made a form (record source = tblPtojects) containing all...

how can i copy a document to a CD without making it read only?
HOW CAN I COPY A DOCUMENT TO A CD WITHOUT MAKING IN READ ONLY? You can't. It is not the file, but the media, that is read only. Even CD-RW media does not allow editing a file on the CD. Copy te file from CD to HD, mak edits and if a CD-RW you should be able to burn the edited file back to the CD. hth "DON" wrote: > HOW CAN I COPY A DOCUMENT TO A CD WITHOUT MAKING IN READ ONLY? ...

Workbook I used yesterday crashes Excel today
I did a lot of work in an Excel workbook yesterday but today I cannot access it. A M$ apology screen comes up saying that Excel has a problem and will have to close. I have the same problem whether I try to open the file from a workstation or the server and a local copy on the workstation gives the same distressing outcome. Excel works fine with other files except for one other which I also need to use desperately. Windows XP Pro Excel 97 I have already tried: shortening the filename opening the backup instead defragmenting hard drives searching for spy and advertising software (Nor...

Unable to Read Japanese Email
I correspond with several Japanese users and can read emails from some of them without a problem, but emails from others are nothing but a series of ?????. In one case, I can read one email but not another from the same sender. Changing the Encoding doesn't help. Sending emails in Japanese to them without a problem...they can read it fine. Would appreciate any suggestions/solutions as I'm stumped. I'm using Outlook 2003 on a Windows XP Home operating system. Japanese language support is installed. ...

Transferring read e-mail to another folder
Hello I was wondering whether there was a way in which I could automatically transfer my e-mail that has been read into another folder, such as "Old e-mail" or something like that? Thanks ...

Leave mail on ISP using exchange
Hello, I am trying to figure out a way for exchange to leave mail at the ISP. I have a user who is used to using POP3 and wants to look at his mail at work using exchange and wants to use POP3 at home. The only thing that I can think of is to create another account at the ISP and alias the mail to that account and then for exchange not to download that mail. Thank You, Joe Bucar Set up a VPN and have him pop it from your Exch server. or better yet, have him use OWA. On Mon, 20 Sep 2004 18:48:20 -0400, "Joe Bucar" <jbucar@hotmail.com> wrote: >Hello, >I am trying ...