xmlreader

Deserialize Xml Using XmlReader and Class from xsd.exe

不问归期 提交于 2019-12-10 19:46:15
问题 OK I have hit a snag trying to learn XmlSerializer while going through some tutorials. I have followed all the recommended steps but my program is not returning anything, or is returning null. I created an XML file as follows: <?xml version='1.0' encoding='UTF-8' ?> <WeeklyJobs> <DailyJobs Date = "02/03/2012"/> <DailyJobs Date = "02/04/2012" TotalJobs = "2"> <Jobs> <Job JobName = "Job Name" Description = "Description"/> <Job JobName = "Job Name" Description = "Description"/> </Jobs> <

Passing XML resource to XMLReader

一个人想着一个人 提交于 2019-12-10 18:45:21
问题 I am trying to pass a .xml file from my res folder to an XMLReader in order to parse it to an object: private void parseXML() { String parsedData = ""; try { Log.w("AndroidParseXMLActivity", "Start"); /** Handling XML */ SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); QuestionXMLHandler myXMLHandler = new QuestionXMLHandler(); xr.setContentHandler(myXMLHandler); InputSource inStream = new InputSource(); Log.w(

Using PHP's XMLReader, how do I get the line number of the current node?

泪湿孤枕 提交于 2019-12-10 18:32:01
问题 Using the XMLReader XML parser in PHP 5.3, I need to get the line number of the current node. A column number or total offset from the beginning of the file would be nice, too. Hopefully I don't have to use some hack like parsing every raw node string for newlines (with readOuterXML() ), but I don't see a getLineNo() property like in the DOM... 回答1: See XMLReader::expand which returns a DOMNode element, which in turn supports getLineNo() 来源: https://stackoverflow.com/questions/2530679/using

XmlReader ReadStartElement causes XmlException

冷暖自知 提交于 2019-12-10 13:35:53
问题 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 the way. Basically, here is a sample of the format of the Xml I am using: <?xml version="1.0" encoding="utf-8" standalone="no"?> <root> <EmptyElement /> <NonEmptyElement Name="NonEmptyElement"> <SubElement Name="SubElement" /> </NonEmptyElement> <

Tell StructureMap to use a specific constructor

故事扮演 提交于 2019-12-10 12:27:58
问题 I have two services that require an XPathDocument . I want to be able to define named instances of XPathDocumnet to use in the configuration of the two services. I also want to be able to tell StuctureMap which constructor of XPathDocument to use. When I try to get an instance of XPathDocument it tells me that it can't find the plugged type for XmlReader . I want to use the constructor that requires a string uri for the xml file. I cannot seem to get this to work. Here is the StructureMap

Why filestream not closed by xmlreader

时间秒杀一切 提交于 2019-12-10 04:17:10
问题 So I am using the filestream inside xmlreader using (XmlReader reader = XmlReader.Create(new FileStream(archivePath, FileMode.Open), readerSettings)) { reader.close() } However, the file feed into the xmlreader still in the lock state after the using scope, weird, I thougt the xmlreader is going to close the filestream for me, is it not? Thanks for help. 回答1: Have you tried this? using(var stream = new FileStream(archivePath, FileMode.Open)) using(var reader = XmlReader.Create(stream,

How to get value from a specific child element in XML using XmlReader?

有些话、适合烂在心里 提交于 2019-12-10 03:05:59
问题 Here's the XML string. <?xml version="1.0" encoding="utf-16"?> <questionresponses> <question id="dd7e3bce-57ee-497a-afe8-e3d8d25e2671"> <text>Question 1?</text> <response>abcdefg</response> <correctresponse>123</correctresponse> </question> <question id="efc43b1d-048f-4ba9-9cc0-1cc09a7eeaf2"> <text>Question 2?</text> <response>12345678</response> <correctresponse>123</correctresponse> </question> </questionresponses> So how could I get value of <response> element by given question Id? Say, if

Parse xml in c# : combine xmlreader and linq to xml

浪子不回头ぞ 提交于 2019-12-09 23:00:37
问题 I have to parse large XML file in C#. I use LINQ-to-XML. I have a structure like <root> <node></node> <node></node> </root> I would like use XmlReader to loop on each node and use LINQ-to-XML to get each node and work on it ? So I have only in memory the current node. 回答1: You can do something like that: string path = @"E:\tmp\testxml.xml"; using (var reader = XmlReader.Create(path)) { bool isOnNode = reader.ReadToDescendant("node"); while (isOnNode) { var element = (XElement)XNode.ReadFrom

How to stop XMLReader throwing Invalid XML Character Exception

谁都会走 提交于 2019-12-09 17:58:29
问题 So I have some XML: <key>my tag</key><value>my tag value &#xB;and my invalid Character</Value> and an XMLReader: using (XmlReader reader = XmlReader.Create(new StringReader(xml))) { while (reader.Read()) { //do my thing } } I have implemented the CleanInvalidCharacters method from here but as the "&#xB" is not yet encoded it doesn't get removed. The error is being thrown at the reader.Read(); line with exception: hexadecimal value 0x0B, is an invalid character. 回答1: The problem is that you

Prevent XmlTextReader from expanding entities

非 Y 不嫁゛ 提交于 2019-12-09 15:55:31
问题 I am trying to read a XML document without expanding the entities, do some manipulations to it, and re-save it with the unexpanded entities as they were initially. When using the XDocument directly, it fails to load, throwing an exception tell me it has unexpanded entities: XDocument doc = XDocument.Load(file); // <--- Exception // ... do some manipulation to doc doc.Save(file2); Exception: Reference to undeclared entity 'entityname'. Then I tried to pass the XmlTextReader to the XDocument