Questions tagged [xmlreader]

xmlreader - Represents a reader that provides fast, noncached, forward-only access to XML data.

Represents a reader that provides fast, noncached, forward-only access to XML data.

More

1120 questions
8
votes
3 answers

How can I force compliance with a given schema in .NET?

Let's say I have a schema with which I want an input document to comply. I load the file according to the schema like this: // Load the ABC XSD var schemata = new XmlSchemaSet(); string abcSchema = FooResources.AbcTemplate; using (var reader = new…
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
7
votes
3 answers

How to omit the xml declarations when using XElement.Save?

XElement.Save actually does what I need but it starts the file with: Is there a way to prevent this? Should I save using other types, methods after I finish creating my XElement? Or should I be skipping that…
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
7
votes
4 answers

How to specify timeout for XmlReader?

I am reading rss with xml reader. And when url is bad it takes 60 seconds to fail for it. How i can specify timeout? using (XmlReader reader = XmlReader.Create(url, settings))
st78
  • 8,028
  • 11
  • 49
  • 68
7
votes
2 answers

Do I need to Dispose XmlReader if I Dispose its underlying Stream?

I have the following method GetData that creates a StreamReader from a file. private void GetData(string file) { string filename = Path.GetFileNameWithoutExtension(file); XmlDocument xmldoc = new XmlDocument(); using (StreamReader sr =…
Leonard Thieu
  • 785
  • 1
  • 7
  • 21
7
votes
5 answers

XmlReader breaks on UTF-8 BOM

I have the following XML Parsing code in my application: public static XElement Parse(string xml, string xsdFilename) { var readerSettings = new XmlReaderSettings { ValidationType = ValidationType.Schema, …
Matt Mills
  • 8,692
  • 6
  • 40
  • 64
7
votes
1 answer

Deserializing a single element in a large XML document: xmlSerializer.Deserialize(xmlReader.ReadSubtree()) fails due to namespace issues

I am attempting to process a large XML document (using a XmlReader) in a single pass, and deserialize only certain elements in it using an XmlSerializer. Below is some code and a tiny mock XML document showing how I have attempted to do…
stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
7
votes
1 answer

xmlwriter as input for xmlreader

I am trying to create a xml-structre from a name/value-pairs. This works with a xmlwriter. Now I would like to transform this xml. I think that the best way is to use the xmlwriter as source for the xmlreader to to the transform. But I don't know…
user1099480
  • 187
  • 1
  • 4
  • 11
7
votes
3 answers

Using XmlReader class to parse XML with elements of the same name

I'm re-writing some code that uses a XmlDocument to parse some XML. I want to use a XmlReader instead to see if I can get some performance improvements. The structure of the XML looks like this:
Matt Puleston
  • 95
  • 1
  • 2
  • 8
6
votes
4 answers

c# whitespaces issue with XmlReader

I have a simple xml value1 value2 I'm using IXmlSerializable to read and write such xml with DTOs. The following code works just fine XmlReader reader; ... while( reader.Read() ){ …
scibuff
  • 13,377
  • 2
  • 27
  • 30
6
votes
1 answer

XmlElement.SelectNodes(..) - finds nothing.. Help?

Sorry to bother you with such a simple question, but I'm stuck here since an hour: I have an xml file that looks something like this: Foo
Efrain
  • 3,248
  • 4
  • 34
  • 61
6
votes
1 answer

Read a namespaced attribute from a SimpleXmlElement (imported from XMLReader)

I'm trying to read a large xml file (about 40 MB), and use this data for update the db of my application. It seems i've found a good compromise in terms of elapsed time/memory using XMLReader and simplexml_import_dom() but i can't get the value of…
Luciano
  • 1,455
  • 8
  • 22
  • 52
6
votes
1 answer

XmlReader ReadStartElement causes XmlException

I'm writing a file reader using the XmlReader in a Silverlight project. However, I'm getting some errors (specifically around the XmlReader.ReadStartElement method) and it's causing me to believe that I've misunderstood how to use it somewhere along…
Samuel Slade
  • 8,405
  • 6
  • 33
  • 55
6
votes
1 answer

Performance: XmlSerializer vs XmlReader vs XmlDocument vs XDocument

I'm working on a little web project and would like to read/write to an XML file. Performance is my first priority. I've come to this great post on comparing the mentioned approaches except XmlSerializer. I prefer XmlSerializer since it makes the…
Kamyar
  • 18,639
  • 9
  • 97
  • 171
6
votes
4 answers

Why is the XmlReader skipping elements?

Please note this question is specific to XmlReader and not whether to use XDocument or XmlReader. I have an XML fragment as: private string GetXmlFragment() { return @"
babayi
  • 85
  • 4
6
votes
1 answer

How to stop XMLReader throwing Invalid XML Character Exception

So I have some XML: my tagmy tag value and my invalid Character and an XMLReader: using (XmlReader reader = XmlReader.Create(new StringReader(xml))) { while (reader.Read()) { //do my thing …
JKennedy
  • 18,150
  • 17
  • 114
  • 198