Click here to Skip to main content
15,891,846 members
Everything / XmlReader

XmlReader

XmlReader

Great Reads

by Dirk Bahle
Tips & Tricks on De/Serializing object graphs with XML
by Paul Schwartzberg
Formatting XML in a string for visual presentation.
by ASP.NET Community
XML namepace has XmlWriter class to write to XML file. Code in C#:using System.XML; //Add this namespace to use XmlWriter and XmlReader
by John Orendt
Prepares play list elements for burning to CD or DVD or loading onto a MP3 player.

Latest Articles

by Dirk Bahle
Tips & Tricks on De/Serializing object graphs with XML
by Altaf Ansari
Converting XML Data into DataTable and Exporting DataTable into Excel File
by Shuqian Ying
Client side data provider for data importing to a relational data service build for StackExchange data dump.
by ASP.NET Community
XML namepace has XmlWriter class to write to XML file. Code in C#:using System.XML; //Add this namespace to use XmlWriter and XmlReader

All Articles

Sort by Updated

XmlReader 

15 Oct 2023 by Member 12760369
Dim nodeDescription As XmlNode = m_xmld.SelectSingleNode("//cbc:Description", manager) Dim childDoc = New XmlDocument childDoc.LoadXml(nodeDescription.FirstChild.InnerText.Trim) Valuerem = "" ...
28 Aug 2023 by Richard Deeming
For some bizarre reason, your XML document contains another XML document embedded as a string within a node. Your elements belong to this embedded document; you won't be able to query them from the parent document. ...
28 Aug 2023 by Member 12760369
I am trying to read the contents of an XML file that contains an electronic invoice. For this, I use namespace but I have not been able to extract the data found in the element. The code that I do is the following and...
19 May 2022 by Member 15643017
ComboBox1.Items.Add(node.InnerText)
29 Mar 2022 by enoughIsenough
I have a XML file and it goes as below and I'm trying to bring out the Node Attribute value from Node Value A
29 Mar 2022 by Richard Deeming
Seems simple enough using LINQ to XML[^]: // Values to find: string pin0 = " value0 ", pin1 = null, pin2 = " value2 ", pin3 = null; XDocument document = XDocument.Load("load.xml"); var select = doc.Descendants("Select").Select(s => new { ...
22 Mar 2022 by unipam
Maybe if you try something like this: public string GetSelectValue(string pinValue) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Server.MapPath("load.xml")); XmlElement root = xmlDoc.DocumentElement; XmlNodeList nodes =...
16 Feb 2022 by johnjsm
Hi, I have the below XML data that was created by BizTalk. I'm finding it hard to get specific values out of it. For instance, I'd like to get all ClientOrderNo, Address lines, ComponentPart, SerialNo. Help would be great as I not great with...
16 Feb 2022 by M Imran Ansari
First node is missing in your xml and secondly you can achieve through xPath like below code. i had implemented one for you and other xPaths you can define Dim serverDoc As XmlDocument = New XmlDocument()...
16 Feb 2022 by _Asif_
There is no direct way of returning all required elements. However you can use XPath to get the deepest node(s) and then use node.parent method to read parent elements. A simple XPath could be :...
16 Feb 2022 by Richard MacCutchan
Quote: None of the examples seem to fit what I'm looking for The chances of you finding a sample that exactly matches your requirements or fairly low. You need to loo at the XmlReader Class (System.Xml) | Microsoft Docs[^]. It contains methods...
2 Apr 2021 by Adi Mirza
I am new in programming and learning new things following online tutorials and you guys. Nowadays! I am reading and learning about LINQ to XML, I have XML followings that have some element/attribute, how to write a query that retrieves data in...
1 Apr 2021 by #realJSOP
I think you're better off using serialization. The topic of serialization is honestly too big to cover in a QA answer, but it's easy to find info on the google machine. There's a lot of prep to use it correctly, but once you've got your entities...
24 Jan 2021 by RickZeeland
This shows how you can get the values: //using System.Linq; //using System.Xml.Linq; XDocument xdoc = XDocument.Load("MyFile.xml"); foreach (XElement node in xdoc.Root.Descendants()) ...
23 Jan 2021 by Sơ Mi Tv
I am writing an application that converts XML file to TAR file. I tried using XmlReader for conversion. but the problem I got at "repairStatus" is in the content. There are 2 cases in the file are "Repaired" and "False Call" I cannot split them...
21 Jan 2021 by RickZeeland
You can generate classes here: Xml2CSharp.com | Convert your XML Examples into XmlSerializer compatible C# Classes[^] The rest is up to you :) Example: using System; using System.Xml.Serialization; using System.Collections.Generic; namespace...
13 Dec 2020 by rezaeti
hi i have a simple app vb.net that use sql2008 as bank and xml file that save connection string items . the password item saved encrypted in xml but when i will read and call xml data to open sql database i see this error my code :Imports System.XmlImports System.IOImports...
26 Nov 2018 by Member 14067398
Hi All, I want to read below xml data.
10 Jun 2018 by Sumit Kumar Singh India
Hello Guys,I have a XML Document which contains multiple tables. i unable to read it in a dataset(i am able to read xml document which contains single table)Exception Error Message:Cannot add constraint to DataTable 'srgbClr' which is a child table in two nested relations....
27 Feb 2018 by Graeme_Grant
Firstly, you have an error in the XML data sample on line# 443. I would map classes to the XML data and convert. But it you want to manually read the xml data, then you could do something like this: var doc = XDocument.Parse(rawXml); var products = doc.Descendants() ...
14 Feb 2018 by Member 13638770
When We are trying to load the XML file into oracle table we are getting the below error. ORA-31061: XDB error: XML event error ORA-19202: Error occurred in XML processing In line 1 of orastream: LPX-00210: expected '
12 Jan 2018 by Member 13545401
my que is I have create one xmlfile that xml file i will store multiple username and password on based of that username and password i want to display hard-drive information can help me to write code to fetch directly That inforamtion through that code! What I have tried: getting simple code...
12 Jan 2018 by CHill60
Start your research with some of the excellent articles[^] here on CodeProject. Then, have an attempt at doing the work for yourself. If you have any problems then please do come back with a new question but remember to post the code that you are having the problems with, and a full...
22 Dec 2017 by Dirk Bahle
Tips & Tricks on De/Serializing object graphs with XML
27 Nov 2017 by Altaf Ansari
Converting XML Data into DataTable and Exporting DataTable into Excel File
2 Jul 2017 by RickZeeland
Take a look at "PDF File Writer C# Class Library" PDF File Writer C# Class Library (Version 1.19.1 Enhancement: Document links)[^] And: "Creating PDF documents from XML": Creating PDF documents from XML[^] Example on GitHub: Example of generating PDF documents[^]
2 Jul 2017 by Member 13289699
In my windows Form application I have one text box in which i need to enter proper HTML tag and now I need to load data in text box into a XML reader then I need to process each element recursively.After this I have to generate a PDF file which contains for example like if i entered , tags the...
8 May 2017 by Member 2127939
The code below currently works and loads XML into a class structure. This structure consists of a collection of items (items), each that have fixed properties and a collection that I use for a variable number of properties. Two things I want to do: 1) I want to change the list into something...
8 May 2017 by Richard Deeming
Assuming the elements in your XML file are actually cased correctly, and the missing closing elements are present, you just need to change the type of your KVPS property from: List> to List> You're currently using the built-in...
5 May 2017 by Wessel Beulink
Should be: For Each node As XmlNode In nodes Dim name = node["NAME"].InnerText cbxList.Items.Add(Name) Next
5 May 2017 by User 4180254
Try with below code snippet it will resolve your issue - Dim RA_File As String = "E:\XMLFile1.xml" ComboBox1.Items.Clear() Dim xmlDoc As XDocument = XDocument.Load(RA_File) Try For Each node As XElement In xmlDoc.Root.Descendants("RISKITEM") ...
19 Jan 2017 by chiomajoshua
Good Day Everyone. Please I Am Relatively New To C# Programming. Please I Want To Send A Request To An API and It will likely return the response in XML Format. Just One Value. Please How Do I Send The Request And Also Parse That Response To My TextBox.Please I am just a beginner to C#. Thank...
19 Jan 2017 by johannesnestler
Nothing yet to help you....1. Learn coding basics for the given language/environment2. Learn the technology for your for your specific problem: like, Services, TCP, XML-Parsing and creation...3. Write code to solve your problem4. If you get stuck - come here again (or ohter place to...
20 Dec 2016 by NiteshAgarwal
I have a large xml file that I need to open and needs to add node inside the node in the existing file.Below is the format of my...
20 Dec 2016 by Patrice T
If you think about it, your file...
20 Dec 2016 by Mehedi Shams
Hi Nitesh,I am providing my solution based on C file pointer approach in C#.Logic:1) Open the file in a stream.2) Move the file pointer to the last employee node.3) Add a new node there.First two points are accomplished here:FileStream FStream = new...
20 Dec 2016 by Dave Kreskowiak
You can't append data to an XML file. Why? Because the data you append will be outside the closing tag of the root tag of the document, thereby invalidating the format of the XML file.You MUST insert this data using XML methods, not file methods, as you've already been told in the comments.
12 Jul 2016 by ebie147
hi guys so i got a datagridview that has a dataset that is linked to a xml file,I got to display the data in the datagridview but what i want to do now is take out rows that has certain values,this is my code'Load Creditors data Dim CPADataset As New DataSet Dim...
23 May 2016 by an0ther1
Your XML is not well formed, CDATA should be as follows;NOTXML elements and nodes are selected using XPath - refer below link;XML and XPath[^]Easiest method of getting the exact nodes you want is;XmlDocument myDoc = new...
19 May 2016 by Muhammad Islam Manzoor
How to read the data from and display in a asp form drop down list.What I have tried:
16 Apr 2016 by Ma'd Saeed
How to create xml file in java using Database Query?Like: "SELECT * FROM Emp"What I have tried:How to create xml file in java using Database Query?Like: "SELECT * FROM Emp"
16 Apr 2016 by Richard MacCutchan
See https://docs.oracle.com/javase/tutorial/jaxp/xslt/writingDom.html[^].
24 Feb 2016 by Manas_Kumar
Try with below code:string xmlData = @" Dominic Crossroad Android 1522 dominicroad 1.0.0, 1.2.0i, 2.0.0j
24 Feb 2016 by satrio_budidharmawan
Hi, I am newly working with XML files with C#, currently I am facing a problem about editing a specific value from XML file.Let's say I have this XML file (plist.xml) : Dominic Crossroad Android ...
25 Oct 2015 by Patrice T
Yes, there is an error in your xml node.Replace/XMLAuthenticateRequest>withorIn html, are always paired.
25 Oct 2015 by Renjith Kalarikkal
I want to add a node in the XML without any value. /XMLAuthenticateRequest>Then i need to make a digital signature of the whole XML and the result should be appended in the node ,XMLAuthenticateRequest'But when i try, the xml node XMLAuthenticateRequest appears...
17 Sep 2015 by Sergey Alexandrovich Kryukov
.NET FCL offers different ways to parse XML. This is my short overview of them:Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.See...
17 Sep 2015 by Patrice T
Solution 1: Hire a real programmer.Solution 2: DIY, Start working, learning the language.If you just want code, you, are at the wrong place. We don't do homework.By the way, you did not even tell which value you want to read, so even someone wanting to do your homework would be unable...
4 Sep 2015 by usernetwork
this is my code can i improve it .namespace ConsoleApplication1{ class Program { static void Main(string[] args) { ReadEJFile("E:\\a.txt"); } private static void ReadEJFile(string filename) { Stopwatch sw =...
3 Sep 2015 by Sergey Alexandrovich Kryukov
The tags of your questions suggest correct approach: use XmlReader. It presents no limitations to the memory resources consumed, because it does not parse anything to memory. I think there is no a way to significantly increase the speed of processing compared to this approach.At the same...
3 Sep 2015 by usernetwork
I have a very large XML file of 6 GB size i want to read it and write its output in multiple files .I am currently using XmlTextReader and its taking 30 mins .Please suggest some ways to reduce the processing time .
7 Aug 2015 by Richard Deeming
You have called the MyDStr function in the wrong place:reader.ReadToFollowing("Pwd")output4.AppendLine(MyDStr(reader.ReadElementContentAsString()))
25 May 2015 by Mohammad Adi
"here url xml"**And it's my controller** [HttpGet] public JsonResult getXMLrequest() { var response = new HttpResponseMessage(); var urlDJP = Request.QueryString["urldjp"]; var data = new VatInRecieveModels(); ...
14 May 2015 by Maciej Los
The error message is quite understandable. Please, refer xml documentation: Extensible Markup Language (XML) 1.1 - documents[^]:Quote:[Definition: There is exactly one element, called the root, or document element, no part of which appears in the content of any other element.] For all other...
14 May 2015 by Andy Lanng
Here is a threaded version of your code: private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode) { //XmlNode xNode ; TreeNode tNode ; XmlNodeList nodeList ; int i = 0; if (inXmlNode.HasChildNodes) ...
14 May 2015 by dinesh_redhawk
Hello Friends,I need to display a large XML file (>21MB) in a tree view control in a C# Windows Form application. I have written the code which is working for small XML files but when i am trying to open a BIG XML file (>1 MB), its taking too much of time.Can anyone suggest how i can...
13 May 2015 by ShaHam11
There are two buttons. When I click first button the startdocument and the other contents will be created and then when I click second button it has to append the content and save the file . But when I click i get an error . "Invalid xml document and document needs a root element.using...
28 Apr 2015 by Lalyka
I am writing a XML validator with xsdbelow is what I did,but when I reach the line while (list.Read()) it gives me the error "There is no Unicode byte order mark. Cannot switch to Unicode." can anybody help me fix it?public class Validator { public void Validate(string...
10 Apr 2015 by Varun Das
private void button1_Click_1(object sender, EventArgs e) { string s = ""; byte[] bytes = Convert.FromBase64String(s); System.IO.FileStream stream = new FileStream(@"D:\file.pdf", FileMode.CreateNew); ...
10 Apr 2015 by Sergey Alexandrovich Kryukov
In addition to Solution 1:The content of XML should also be consistent with the actually applied encoding. With UTF-8, this is how your prolog should look:There is one delicate thing here: the BOM. First, read about...
10 Apr 2015 by Mario Z
This line doesn't make sense:string send = Encoding.GetEncoding("utf-8").GetString(Encoding.GetEncoding("utf-8").GetBytes(send));You see in .NET String is a collection of Unicode characters (or in better words a collection of Unicode code points) that represent a text which is encoded by...
10 Apr 2015 by Andrey Golubtsov
Hi all .I have a string with a XML text and i want to save it like XML. I encoded string (to "utf-8") but when i want to make XML from that - my cyrillic symbols in Value don't displayed right . What i need to do to encode my XML document ?part of my xml : Мои...
8 Apr 2015 by Varun Das
I need to pass a varchar field in a table to my windows form and change it on a button click to pdf file as output,my requirement is due to the extensive varchar size in the field so i need it to convert it into pdf
8 Apr 2015 by OriginalGriff
Try:using (SqlConnection con = new SqlConnection(strConnect)) { con.Open(); using (SqlCommand cmd = new SqlCommand("SELECT myPDFData FROM myTable", con)) { using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) ...
6 Apr 2015 by CHill60
Your code is getting them all.levels is of type "System.Linq.Enumerable+WhereEnumerableIterator`1[System.Xml.Linq.XElement]" so it contains a "list" of the matching nodes.You can filter it further on the read var levels = from levl in xmlDoc.Descendants() where...
3 Apr 2015 by Mario Z
Don't use Maciej approach, you will definitely get an OutOfMemoryException exception if you are expecting an XML file of +5GB.Also that second approach in which you are using the XmlTextReader is a right way to go, that is the only way you can read XML without loading an entire document at...
2 Apr 2015 by Maciej Los
Please, read my comment to the question.I'd suggest to use Linq, but i need to warn you. If a portion of data is huge, the performance of below code might be unsatisfying.var qry = xDoc.Element("backup") .Descendants("project") .Descendants("issues") ...
2 Apr 2015 by Sriram Mani
Hi,Is there a logic to search for a particular value in an XML file without loading it in memory? XML Document is working fine for my requirement. But I want the file to be handled without loading into memory since the actual XML file might be sized to 5GB+.XMLReader is the alternative I...
11 Mar 2015 by Ganesh KP
If your question is to create a new xml file then have a look at this link C Sharp Informationsor Stack Overflowor Mind Fire Solutionsif you are looking for how to read xml file then have a look at the below linksC Sharp Informations To ReadA simple google search gives...
11 Mar 2015 by RajeeshMenoth
Hi,Read This Tutorials..1) XSD Overview2) XSD Date and Time Data Types
11 Mar 2015 by Brinda Lakhani
hello friends,I am new to xml. I want to specify the time duration in .xml file for my c# application. This is my code. I don't know. is it correct or not. ...
29 Oct 2014 by czar cruz
here's my working example, though albeit near to your request, but this might give you hint how to extract data from the node up to the last one...Dim xmlDoc As New System.Xml.XmlDocumentxmlDoc.Load("d:\product.xml")Dim xmlNode As System.Xml.XmlNodeList =...
21 Oct 2014 by BillWoodruff
Once you get rid of the "~" and get the file path right, check whether the File exists before you try to read it, and do something appropriate if it does not exist:string YourFilePath = @"C:/SomeDirectory/SomeFile.xml";if(! File.Exists(YourFilePath)){ throw new...
21 Oct 2014 by Sergey Alexandrovich Kryukov
This is not a valid file name. You cannot use "~". If you remove '~', it will mean the file path starting from the root directory on the current volume (bad idea, anyway). Moreover, there are no situations when using hard-coded file paths can be useful. Path names should always be calculated...
21 Oct 2014 by anurag19289
I added a xmlfile in my solution.I was trying the below programusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Xml;namespace ReadingXML{ class Program { static void Main(string[] args) { ...
18 Oct 2014 by Member 11162702
2014-10-17 12:30:47,830 INFO [STDOUT] org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxUnexpectedCharException: Illegal character ((CTRL-CHAR, code 25)) at [row,col {unknown-source}]: [1,5090]2014-10-17 12:30:47,830 INFO [STDOUT] at...
29 Sep 2014 by wanrnerlego
A simple...C# XML ReaderWarner
15 Sep 2014 by phonemyatt
Hi Folks,I've been finding the right way to parse the following Xml file in my android and I can't make the decision. Please give me some advise. I got the following XML files which is going to display in my android app.
25 Aug 2014 by hrishisinha
Hi all,I was using xmlreader to read the xml to create datatable for me.While coding from the local path the execution speed was very fast.I used the code like below: XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; ...
25 Aug 2014 by Nathan Minier
The GC shouldn't be collecting the stream from the service, but it's not impossible and would certainly explain the observed behavior.We might be able to fix this by explicitly putting the results of the service into a memorystream.using(var theStream = new...
14 Aug 2014 by KarstenK
if you really know what you want, you can read the xml as text and parse it.Else you must use a xml parser. Consider trying out this one. Looks like it can suit your needs.
13 Aug 2014 by Yogesh Kumar Tyagi
view this link for mvc tree view How to Create TreeView in MVC3[^]i think it will help you.Build a custom MVC Tree Control by using jsTree[^]
12 Aug 2014 by angiangi
I'm trying to get nested hierarchy data from large XML file and show it in a tree structure in MVC application.I need to considerate performance issue as well, because I'm using a large xml file.I started with parsing the xml with XmlReader and now i thinking to use XmlSerializer, what do...
11 Aug 2014 by Jeroen van Veen
Hi, I have the following array: items = new DisplayButton[10, 6]; items[0, 0] = time0; items[0, 1] = delay0; items[0, 2] = direction0; items[0, 3] = spoor0; items[0, 4] = type0; items[0, 5] = warning0; items[1, 0] = time1; items[1, 1] = delay1; items[1, 2] = direction1; items[1, 3] =...
4 Jul 2014 by Rob Philpott
Normally you'd break out of it. But what I'd be inclined to do here is put the while loop in its own method, and use a return to get out of that.An alternative would be to create a Boolean, and set it where you want to exit. Use the Boolean in an 'and' condition in the while statement.
4 Jul 2014 by chellapandi160
Hi, Kindly help me, How to While loop Exit . I indicated place,,,using (XmlReader reader = XmlReader.Create(new StringReader(recievedXML), xrs)) { while (reader.Read()) { if (reader.IsStartElement()) { switch...
10 Jun 2014 by Kornfeld Eliyahu Peter
I can't understand why you are using some 3rd party extension to serialize an object to XML, but if this is a requirement then go and ask the 3rd party for support!If you can choose your way, than you be better with the simple .NET way of XML serialization (and deserialization)...Start...
10 Jun 2014 by Harshad Gharote
I have this code which converts an object to xmldocument but while doing that i get this error The code is which returns the xmldocument is below :public static XmlDocument ToXmlDocument(this MyClass myclass) { var result = new XmlDocument(); var xml =...
24 May 2014 by Maciej Los
Sorry, but no one wants to analyze your XML file.Please read my answer to your previous question: Error while converting xml to excel in vb.net[^]As i wrote there, you can open XML via Excel application. Follow the links i provided. There you'll find many usefull information about opening...
5 May 2014 by Shuqian Ying
Client side data provider for data importing to a relational data service build for StackExchange data dump.
24 Apr 2014 by phil.o
Examples: Using OPENXML[^]OPENXML (Transact-SQL)[^]Beginner sample codes for the Open XML SDK?[^]And these are just the three topmost results you can get.Maybe you could have a look at them, try to apply given examples, and see from here if there's still something missing to...
24 Apr 2014 by Sarath02
Hi,I want to read xml file to spreadsheet using open xml sdk. if anyone knows please help me.....
15 Apr 2014 by Suresh Palanisamy
Hi all,I am just doing to start working in VB.Net. I want to separate the normal values alone in my XML datatype in SQL 2008.I Couldn't able to read the xml data types and separate the values.Please help me to get out this problem.XML Data in my...
10 Apr 2014 by Steve Van Lint
eHi,I'm not the most experienced person around here to answer this but I'll try.First, I believe that the structure of you XML needs to looking into.Do you expect more than 1 value in your ProductVariantAttributeValue element?If not, then you could just leave out the Value...
10 Apr 2014 by STP_Martin
Hi I have the following XML string example:12
10 Apr 2014 by gggustafson
In the following fragment, load_training_data does what you want using XPath[^].using System;using System.Collections.Generic;using System.Windows.Forms;using System.Xml;namespace LoadingFace { public partial class LoadingFace : Form { ...