.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

xmlreader in asp.net

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :WPF

when we read xml file using xmlreader  in asp.net

dim xmlpath="text.xml"

dim XReader =

New XmlTextReader(xmlpath)

I want to know that when it is reading, can i modify the xml file (txt.xml)?

Is there any to control this?

And what does mean by read only access of the xml file.



Rahul Maurya

View Complete Post

More Related Resource Links

Unable to read my RSS feed with XmlReader



I have an RSS-feed page, which I developed with SyndicationFeed class. The page seems to work, and if I type the url into a browser, a page similar to this opens up: http://msdn.microsoft.com/en-us/magazine/rss/default.aspx

However, I'm unable to read the feed into an XmlReader object. Let's say my rss page is "http://mysite/rss.aspx", and my code in the rss-retriever side is something like this:

XmlReader reader = XmlReader.Create("http://mysite/rss.aspx");

XmlDocument doc = new XmlDocument();


I get an error on doc.Load(reader) method:

For security reasons DTD is prohibited in this XML document. To enable DTD processing set the ProhibitDtd property on XmlReaderSettings to false and pass the settings into XmlReader.Create method

I've tried to set the ProhibitDtd to false, but then I get some other error.

If I put something like this, I can save the xml dat into a file, and I can see that it's just like it should be:

XmlReader reader = XmlReader.Create("http://mysite/rss.aspx");

SyndicationFeed feed = new SyndicationFeed();

XmlReader.Create(textReader, XmlReaderSettings) Validation Issue

For the most part, when I perform an XmlReader.Read() I am catching validation errors based on my schemas.  This, however, is a large group of schemas with several imports and includes.  My question is why I'm having validation errors in two places that seem to be defined in the schema.   Here's an example:   Schema 1 (you can see that IdentificationType has sub-elements for IdentificationID and IdentificationCode):   <xsd:complexType name="IdentificationType">                 <xsd:annotation>                         <xsd:documentation>A data type for a representation of an identity.</xsd:documentation>                         <xsd:appinfo>                                 <i:Base i:namespace="http://niem.gov/niem/structures/2.0" i:name="Object"/>               &nb

Issue travasering xml document with XmlReader

hi asp.net 4.0, visual studio 2010 I'm having trouble looping through the contens of the xml document using XmlReader. The problem is not exactly with xml but it lies in how to create this loop. Below I've posted an example of the code.  This is the problem: When reader.Name == "car" I know it's on the beginning of a new xml node in the xml file. Then the loop loops through and set the values to the rest of the values for the item object. Once again if reader.Name == "car" and item has a value, then the item is added to the returnlist. So basically I'm looking for ideas to make this code cleaner and safer (less likely to fail). I'm new to xml and this code looks terrible. I don't like the idea that I don't find all the data to one Car object in one loop, instead I have to use multiple loop runs before I get all the data. I coould use XmlDocument if that is cleaner, it's slower but the xmlfile is so little that no user is able to notice a differencereturnList List<Car> = new List<car>();Cars item; while (reader.Read()) { if (reader.Name == "car") { if (item != null) returnlist.Add(item); item = new Car(); } else if (reader.Name == "model") { item.Model = reader.Value; } else if (reader.Name == "engine") { item.Engine = reader.Value

XmlReader.Create() always {None}


Hi all,

Can anybody explain why does XmlRader.Create() always return {None}?

MemoryStream memStream = new MemoryStream();
byte[] data = Encoding.Unicode.GetBytes("<root><item>Demo</item></root>");
memStream.Write(data, 0, data.Length);
System.Xml.XmlReaderSettings xmlSettings = new XmlReaderSettings();
xmlSettings.ConformanceLevel = ConformanceLevel.Fragment;    // Can be document - it changes nothing
xmlSettings.IgnoreWhitespace = true; xmlSettings.IgnoreComments = true; XmlReader a = XmlReader.Create(memStream, xmlSettings); // First try with MemoryStream
XmlReader b = XmlReader.Create(new StringReader("<root><item>Demo</item></root>"), xmlSettings); // Second - with TextReader

Actual result : a = {None}, b = {None} .. all fields of created XmlReader are empty! Why?

Thanks for replies.

Using XMLReader and XMLWriter to read and write to a config.xml file


I have a c# program, and I have created an initialization.xml with some attributes.  One of the attributes is an output directory location that the user enters.  I want to be able to open the init file and write this directory path to the outputLocation attribute of the init xml file.

I know how to read xml files using XMLReader and create and write new XML files with XMLWriter, but not sure how to go about open an existing file, moving to a specific attribute, and writing the value to it.

I am assuming this is pretty straight forward.



help in validation with XMLReader


Hi all,

I have an xml file of  the structure

      <elt 1 />
      <elt 2 />
      <elt 3 />
      <elt n />
         <elt C1 />
         <elt C2 />
         <elt C3 />
         <elt Cn />         
         <elt O1 />
         <elt O2 />
         <elt O3 />
         <elt On />         

I am using an xmlreader to validate this xml with an xml schema.  I am finding it difficult to frame a solution for the following problem.

Lets suppose that element 7 in the master element(<elt 7 />) is a non conforming element. the validation code will find it. So far so good, now i want to find the value of the last element within the master element(<elt n />) when there is an error in one of the elements. The same also applies for core and other elements. How do I go about finding a solution for this. The value in the last element will be used in a report of errors in the xml. There can be many "master elements".

The code for validation is as foll

xmlReader getting the values back from a section


 I have an xml file that looks like this:

<?xml version="1.0" ?>
<!DOCTYPE eparcel (View Source for full doctype...)>
- <eparcel>
    - <ratesAndServicesResponse>
        - <product id="1040" sequence="1">
            <name>Priority Courier</name>
        - <product id="1020" sequence="2">

Xml Deserializing a XMLReader feed and capturing the errors if any




I have working piece of code which takes an xml feed and transfers it into an object.  This is all working and was just wondering since I am using an XMLReader is there anyway for me to capture the xml error (say if a date was 20/20/2011) and get the full xml tree that was passed.


I am basically doing the following



this I have wrapped in a try as I want to capture the error and add the failed xml subtree to an errorXml doc that is built up of all the failed updates.


I am not sure how the best way is to get the whole xml sub tree since XmlReader is read forward only?


Would it be best to get the outer xml and then convert it to the object or is there away to get it out of the exception?

XmlReader Security Exception?



I used the following code:

XmlReader reader = XmlReader.Create("AuctionHandler.ashx");
XmlDocument xmldoc = new XmlDocument();

And i get the following exception:

System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessPermission.Demand() at System.IO.Path.GetFullPath(String path) at System.Xml.XmlResolver.ResolveUri(Uri baseUri, String relativeUri) at System.Xml.XmlUrlResolver.ResolveUri(Uri baseUri, String relativeUri) at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext) at System.Xml.XmlReader.Create(String inputUri) at Default.Auctions() in d:\hosting\4646264\html\slauctions\Default.aspx.cs:line 20 The action that failed was: Demand The type of the first permission that failed was: System.Security.Permissions.FileIOPermission The Zone of the assembly that failed was: MyComputer

And i can access thie ASHX file with javascript and read the XML.

just cant do it with ASP .NET...


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend