xmlreader

There is no Unicode byte order mark. Cannot switch to Unicode

六眼飞鱼酱① 提交于 2019-11-28 10:40:06
I am writing an XML validator with XSD. Below is what I did, but when the validator reached 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 xmlString) { Boolean bRet = true; string xmlPath = @"C:\x.xml"; string xsdPath = @"C:\general.xsd"; XmlReaderSettings Settings = new XmlReaderSettings(); Settings.Schemas.Add("", xsdPath); Settings.ValidationType = ValidationType.Schema; Settings.ValidationEventHandler += new ValidationEventHandler

PHP open gzipped XML

不打扰是莪最后的温柔 提交于 2019-11-28 07:46:05
I am struggling to read gzipped xml files in php. I did succeed in reading normal xml files, using XMLReader() like this: $xml = new XMLReader(); $xml->open($linkToXmlFile); However, this does not work when the xml file is gzipped. How can I unzip the file and read it with the XMLReader? As you didn't specify a PHP version, I am going to assume you are using PHP5. I am wondering why people haven't suggested using the built in PHP compression streams API . $linkToXmlFile = "compress.zlib:///path/to/xml/file.gz"; $xml = new XMLReader(); $xml->open($linkToXmlFile); From what I understand, under

Invalid URI: The Uri string is too long

主宰稳场 提交于 2019-11-28 07:08:48
问题 I am trying to grab a schema and validate against my xml. XmlReaderSetting settings = new System.Xml.XmlReaderSettings(); settings.Schemas.Add(null, "http://example.com/myschema.xsd"); settings.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(settings_ValidationEventHandler); settings.ValidationType = ValidationType.Schema; settings.IgnoreWhitespace = false; XmlReader reader = XmlReader.Create(xml, settings); I get Invalid URI: The Uri string is too long System

Read XElement from XmlReader

孤街醉人 提交于 2019-11-28 03:51:18
问题 I'm playing around with parsing an XMPP XML stream. The tricky thing about the XML stream is that the start tag does not get closed until the end of the session, i.e. a complete DOM is never received. <stream:stream> <features> <starttls /> </features> .... network session persists for arbitrary time .... </stream:stream> I need to read the XML elements from the stream without caring that the root element has not been closed. Ideally this would work but it doesn't and I'm assuming it's

How to read an XML File

我是研究僧i 提交于 2019-11-28 02:23:14
I have a VB.net program. I'm attempting to use XMLReader to read a .xml file. I want to break the XML File up to organize it into different "Sections" In this example "FormTitle" and "ButtonTitle" . I would like to grab the <Text> data from FormTitle and display it as the Form "text" and take the <Text> in "ButtonTitle" and have it display in the button text. Here is my XML File: <?xml version="1.0" encoding="utf-8"?> <!--XML Database.--> <FormTitle> <Text>Form Test</Text> </FormTitle> <ButtonTitle> <Text>Button Test</Text> </ButtonTitle> Here is my current Code: If (IO.File.Exists("C:\testing

Why is my new XmlTextReader(stream) reading in many megabytes into memory rather than streaming properly?

痴心易碎 提交于 2019-11-28 02:00:17
问题 I am getting Out of Memory Exceptions when STREAMING in XML into an XmlReader! Looking in a memory profiler we can see that it is calling StringBuilder.Append over and over resulting in tons of 128KB buffers filling all of memory. That's pretty contrary to "streaming". It shouldn't be loading more than one 4KB buffer. 回答1: Reading through the .NET source code, it turns out there's a "v1compat" mode that will indeed read way ahead, defeating the purpose of streaming. So, how do you avoid

Current line number from a System.Xml.XmlReader (C# & .Net)

感情迁移 提交于 2019-11-28 01:47:29
Does anyone know how I can get the current line number of an System.Xml.XmlReader? I am trying to record where in a file I find Xml elements. Take advantage of the IXmlLineInfo interface supported by an XmlReader : IXmlLineInfo xmlInfo = (IXmlLineInfo)reader; int lineNumber = xmlInfo.LineNumber; Expanding on the IXmlLineInfo interface, the documentation for this is pretty bad; from doing a bit of digging, I can tell you the following: 1) System.Xml.XmlReader is abstract, so you're never going to be dealing with an instance of this, as such, the fact that it doesn't implement IXmlLineInfo isn't

Problem - XML declaration allowed only at the start of the document

对着背影说爱祢 提交于 2019-11-28 01:22:07
xml:19558: parser error : XML declaration allowed only at the start of the document any solutions? i am using php XMLReader to parse a large XML file, but getting this error. i know the file is not well formatted but i think its not possible to go through the file and remove these extra declarations. so any idea, PLEASE HELP Make sure there isn't any white space before the first tag. Try this: <?php //Declarations $file = "data.txt"; //The file to read from. #Read the file $fp = fopen($file, "r"); //Open the file $data = ""; //Initialize variable to contain the file's content while(!feof($fp))

XmlReader - problem reading xml file with no newlines

帅比萌擦擦* 提交于 2019-11-28 01:16:46
When I use XmlReader to parse an XML file, I get different results depending on whether the XML file is properly formatted (i.e. with newlines) or not. This is the code I'm using: XmlReader reader = new XmlTextReader(xmlfile); reader.MoveToContent(); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.Name == "entry") { Console.WriteLine(reader.ReadElementContentAsString()); } break; } } And the XML content I've been using is: <xport><meta><columns>5</columns><legend><entry>AVERAGE:host:ed402b4d-71e7-4a8d-be29-ab6e54e955c8:memory_total_kib</entry><entry

getting the current position from an XmlReader

痞子三分冷 提交于 2019-11-27 15:44:35
问题 Is there a way to get the current position in the stream of the node under examination by the XmlReader? I'd like to use the XmlReader to parse a document and save the position of certain elements so that I can seek to them later. Addendum: I'm getting Xaml generated by a WPF control. The Xaml should not change frequently. There are placeholders in the Xaml where I need to replace items, sometimes looping. I thought it might be easier to do in code rather than a transform (I might be wrong