xmlreader

How to get innerXML attribute values using xml reader

拈花ヽ惹草 提交于 2019-12-24 04:54:09
问题 I have a similar situation as the example here How to retrieve the "Price" and "Title" values of a book with given ISBN ? 回答1: Here's an example: class Program { static void Main() { var xml = @" <bookstore> <book genre='novel' ISBN='10-861003-324'> <title>The Handmaid's Tale</title> <price>19.95</price> </book> <book genre='novel' ISBN='1-861001-57-5'> <title>Pride And Prejudice</title> <price>24.95</price> </book> </bookstore> "; using (var reader = new StringReader(xml)) using (var

Using XmlReader get Unauthorized WebException

 ̄綄美尐妖づ 提交于 2019-12-24 00:14:58
问题 When trying to consume an RDF feed from craigslist, I'm running into a (401) Unauthorized WebException. I'm able to read the two commented out URLs directly below it with no issues. If I'm able to directly navigate to the craigslist URL using Internet Explorer with no problem, why does it fail when trying to load the data using an XmlReader? http://portland.craigslist.org/search/sss?query=mac&srchType=A&format=rss static void Main(string[] args) { XmlReader reader = XmlReader.Create("http:/

XmlReader chopping off whitespace after ampersand entity?

爱⌒轻易说出口 提交于 2019-12-23 16:10:33
问题 This is strange. I've got a WCF Message and I'm trying to read the contents of the body into an XmlDocument. The contents of the message body look like this on the wire (when inspected with WCF tracing turned on): <abc> <timeZone>(GMT-05:00) Eastern Time (US & Canada)</timeZone> </abc> The code for the reader looks like this: XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = false; settings.CheckCharacters = false; XmlReader bodyReader = XmlReader.Create(

Java XMLReader not clearing multi-byte UTF-8 encoded attributes

老子叫甜甜 提交于 2019-12-23 10:06:50
问题 I've got a really strange situation where my SAX ContentHandler is being handed bad Attributes by XMLReader. The document being parsed is UTF-8 with multi-byte characters inside XML attributes. What appears to happen is that these attributes are being accumulated each time my handler is called. So rather than being passed in succession, they get concatenated onto the previous node's value. Here is an example which demonstrates this using public data (Wikipedia). public class MyContentHandler

Java XMLReader not clearing multi-byte UTF-8 encoded attributes

China☆狼群 提交于 2019-12-23 10:05:43
问题 I've got a really strange situation where my SAX ContentHandler is being handed bad Attributes by XMLReader. The document being parsed is UTF-8 with multi-byte characters inside XML attributes. What appears to happen is that these attributes are being accumulated each time my handler is called. So rather than being passed in succession, they get concatenated onto the previous node's value. Here is an example which demonstrates this using public data (Wikipedia). public class MyContentHandler

Performance: XmlSerializer vs XmlReader vs XmlDocument vs XDocument

蹲街弑〆低调 提交于 2019-12-23 09:38:42
问题 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 code much cleaner. But I don't know about its performance. What kind does XmlSerializer use inside to write to XML files? 回答1: As for the performance of XmlSerializer, see http://msdn.microsoft.com/en-us/library/182eeyhh.aspx which says: The

I want to edit xml file

泄露秘密 提交于 2019-12-23 05:49:06
问题 I have modified the structure of d xml file. i want to edit value of visible 回答1: You can use such code pattern: bool foobar() { XmlDocument doc = new XmlDocument(); try { doc.Load(FileName); XmlNodeList ns = doc.SelectNodes("a/d/e/f"); if (ns.Count == 1) { ns[0].Attributes["visible"].Value = true; doc.Save(FileName); return (true); } else return (false); } catch (Exception e) { return (false); } } 回答2: Well, LINQ to XML makes it very easy to manipulate XML documents, assuming they're small

How to use XMLReader to parse multiple, identically named attributes of XML element/sub-element

给你一囗甜甜゛ 提交于 2019-12-23 02:45:08
问题 I'm using XMLReader and PHP to process a moderately-sized XML file (6mb) and basically break up the attribute data and insert it into my own database. Problem is, each element has a variable number of subelements with identically named attributes. Here's an example (this is open data about the government courtesy of govtrack.us): <?xml version="1.0" ?> <people> <person id='400001' lastname='Abercrombie' firstname='Neil' birthday='1938-06-26' gender='M' pvsid='26827' osid='N00007665'

problem parsing with XMLReader (using ReadSubTree)

こ雲淡風輕ζ 提交于 2019-12-23 02:34:40
问题 Im trying to build a simple XML to Controls parser in my CF application. In the code below the string im trying to parse looks like this: "<Panel><Label>Text1</Label><Label>Text2</Label></Panel>" The result i want with this code would be a Panel with two labels. But the problem is when the first Label is parsed the subreader.Read() returns false in the ParsePanelElementh method, and so it falls out of while statement. Since im new into XMLReader i must be missing something very simple. Any

Get xml attribute values as string[]

 ̄綄美尐妖づ 提交于 2019-12-22 18:48:10
问题 My xml file has something like this: ... <Keyword name = "if" /> <Keyword name = "else" /> <Keyword name = "is" /> ... So how can I recursively get all of the values of the name attribute and add them to a List<string> or string[] . Maybe a foreach loop? I followed codemeit's and I keep getting an error: Data at the root level is invalid. Line 1, position 1. My xml file is <KeyWords> ... <KeyWord name = "if" /> ... </KeyWord> New problem The '\' character, hexadecimal value 0x5C, cannot be