xmltextreader

Fixing bad XML file (eg. unescaped & etc.) [duplicate]

送分小仙女□ 提交于 2020-01-10 03:34:09
问题 This question already has answers here : How to parse invalid (bad / not well-formed) XML? (4 answers) Closed 2 years ago . I got an XML file from 3rd party that I must import in my app, and XML had elements with unescaped & in inner text, and they don't wont to fix that ! So my question is what is the best way to deal with this problem ? This XML is pretty big and that fix has to be fast, my first solution is just replace & character with ampersand but really I don't like this "solution" for

Getting data from xml by attribute value C# using XmlTextReader

杀马特。学长 韩版系。学妹 提交于 2020-01-06 07:50:30
问题 I have a file with the following content (myfile.xml). I have to get all content coming under (including product node) a product with id=1 . <products> <product id="1"> <category>q</category> </product> <product id="2"> <category>w</category> </product> <product id="3"> <category>e</category> </product> </products>` i.e. the result should be : <product id="1"> <category>q</category> </product> How can I do this? I have the restriction that I should use XmlTextReader or XPathNavigator only for

Getting data from xml by attribute value C# using XmlTextReader

爷,独闯天下 提交于 2020-01-06 07:46:07
问题 I have a file with the following content (myfile.xml). I have to get all content coming under (including product node) a product with id=1 . <products> <product id="1"> <category>q</category> </product> <product id="2"> <category>w</category> </product> <product id="3"> <category>e</category> </product> </products>` i.e. the result should be : <product id="1"> <category>q</category> </product> How can I do this? I have the restriction that I should use XmlTextReader or XPathNavigator only for

The '', Hexadecimal value 0x1F, is not a valid character. Line 1, Item 1

血红的双手。 提交于 2020-01-05 04:43:28
问题 I am getting xml data through an httpwebrequest. The following code was working fine. But something changed and suddenly started to give me an exception on Read() method with error : The '', Hexadecimal value 0x1F, is not a valid character. Line 1, Item 1. In web browser sURL gives me a valid xml. I dont know what changed. HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sURL); req.Method = "GET"; WebResponse response = req.GetResponse(); StreamReader resStreamReader = new StreamReader

why does xmltextreader convert html encoded utf8 characters to utf8 string automatically?

我的未来我决定 提交于 2019-12-31 02:17:28
问题 I receive an XML file with encoding "ISO-8859-1" (Latin-1) Within the file (among other tags) I have <OtherText>Example "content" And ─</OtherText> Now for some reason when I load this into XMLTextReader and do a "XmlReader.Value" to return the value, it returns: "content" And ─ This then, when confronted with a database only accepting Latin-1 encoding, obviously errors. I have tried the following: Converting into bytes and using Encoding.Convert to change from UTF-8 into Latin-1 (which

Name cannot begin with the ' ' character

牧云@^-^@ 提交于 2019-12-21 03:09:08
问题 I'm parsing some XML in C#. I'm getting it from a database, and so converting it to a MemoryStream before reading it with an XmlTextReader. The problem is that I get this error: Name cannot begin with the ' ' character, hexadecimal value 0x20. Line 1, position 3. Following is my XML and my code for reading it (it's coming out of the database alright, no blank first character). Any suggestions? XML: <? xml version="1.0" encoding="utf-8" ?> <form> <e order="0" type="custom" name="test"> <fi

Using XmlTextReader

夙愿已清 提交于 2019-12-19 19:43:52
问题 I am a beginner programmer starting off with C#, and web services. In the Service.cs file of my web service, I create a ReadXMLFile() method where I am trying to read an existing XML file, take the data from it and place it to the corresponding properties (DataMembers) that I created in the IService.cs file. My problem is that my code is basically not doing anything. I've tried looking for web sites and tutorials on this but there really isn't much out there, especially for a beginner like

Reading a xml file multithreaded

倖福魔咒の 提交于 2019-12-12 09:47:23
问题 I've searched a lot but I couldn't find a propper solution for my problem. I wrote a xml file containing all episode information of a TV-Show. It's 38 kb and contains attributes and strings for about 680 variables. At first I simply read it with the help of XMLTextReader which worked fine with my quadcore. But my wifes five year old laptop took about 30 seconds to read it. So I thought about multithreading but I get an exception because the file is already opened. Thread start looks like this

Reading Multiple XML files

江枫思渺然 提交于 2019-12-12 00:30:04
问题 I have Created a small XML tool, to find the numbers of element present in Multiple XML files. This code gives the fine result for the elements which are must in XML files. But when it comes to specific elements, which may be present or not in XML files, Software give me result as: 10/8/2012 11:27:51 AM C:\Documents and Settings\AlaspuMK\Desktop\KS\success\4CPK-PMF0-004D-P565-00000-00.xml Instance: 0 10/8/2012 11:27:51 AM C:\Documents and Settings\AlaspuMK\Desktop\KS\success\4CPK-PMF0-004D

XMLTextReader not reading an element content

杀马特。学长 韩版系。学妹 提交于 2019-12-09 13:05:32
问题 static void ReadXml() { string a= null; double b= 0; double c= 0; XmlReader xmlReader = new XmlReader("Testxml.xml"); xmlReader. using (xmlReader) { if (xmlReader != null) { while (xmlReader.Read()) { if (xmlReader.NodeType == XmlNodeType.Element) { switch (xmlReader.Name) { case "a": a = xmlReader.ReadElementContentAsString(); break; case "b": b = double.Parse(xmlReader.ReadElementContentAsString()); break; case "c": c = double.Parse(xmlReader.ReadElementContentAsString()); break; } } } } }