public void Validate(string htmlFragment) { if (string.IsNullOrEmpty(htmlFragment)) { return; } htmlFragment = "<root>" + htmlFragment + "</root>"; XmlReaderSettings settings = new XmlReaderSettings(); settings.ValidationEventHandler += new ValidationEventHandler(settings_ValidationEventHandler); settings.ValidationType = ValidationType.Schema; settings.Schemas = XmlReaderSettings; settings.ConformanceLevel = ConformanceLevel.Fragment; settings.DtdProcessing = DtdProcessing.Ignore; settings.IgnoreComments = true; //settings.ValidationFlags=XmlSchemaValidationFlags.ProcessSchemaLocation; settings.Reset(); using (var xmlRead = XmlReader.Create(new StringReader(htmlFragment), settings)) { try { while (xmlRead.Read()) { } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
public static string XmlToJson(this string xmlStr) { XmlReaderSettings settings = new XmlReaderSettings(); settings.Reset(); settings.IgnoreComments = true; //byte[] array = Encoding.UTF8.GetBytes(xmlStr); //MemoryStream stream = new MemoryStream(array); //stream.Position = 0; TextReader tr = new StringReader(xmlStr); XmlReader reader = XmlReader.Create(tr, settings); doc.Load(reader); reader.Close(); return(JsonConvert.SerializeXmlNode(doc)); }
private void button2_Click(object sender, EventArgs e) { uint _MCW_EW = 0x8001F; uint _EM_INVALID = 0x10; initStructure(); EncodeStringValueInField(IP.Text, ref teth.IPAddress); EncodeStringValueInField(Porta.Text, ref teth.Port); try { _controlfp(_MCW_EW, _EM_INVALID); IAE17AX_InitEth(ref teth); int c = IAE17AX_Status(ref ecrData, ref tposData); _controlfp(_MCW_EW, _EM_INVALID); XmlReaderSettings settings = new XmlReaderSettings(); settings.Reset(); settings.ProhibitDtd = false; settings.CheckCharacters = false; settings.CloseInput = true; XslCompiledTransform xslt = null; StringReader XLSStringRdr = new StringReader(xsl); XmlReader xslReader = XmlReader.Create(XLSStringRdr, settings); xslt = new XslCompiledTransform(); xslt.Load(xslReader); xslReader.Close(); xslReader = null; xslt = null; MessageBox.Show("OK - nessuna eccezione"); _controlfp(_MCW_EW, _EM_INVALID); IAE17AX_Free(); _controlfp(_MCW_EW, _EM_INVALID); } catch (Exception ex) { MessageBox.Show("Exception:" + ex.Message); } }
public int v3() { string readerType = (string)this.Param; XmlReaderSettings rs = new XmlReaderSettings(); using (XmlReader r = ReaderHelper.CreateReader(readerType, new StringReader("<a/>"), false, null, rs)) { bool cc = r.Settings.CheckCharacters; bool closeinput = r.Settings.CloseInput; DtdProcessing dtd = r.Settings.DtdProcessing; bool ignorecomm = r.Settings.IgnoreComments; bool ignorepi = r.Settings.IgnoreProcessingInstructions; bool ignorewhtsp = r.Settings.IgnoreWhitespace; int lineNumberOffset = r.Settings.LineNumberOffset; int linePositionOffset = r.Settings.LinePositionOffset; long maxcharsindoc = r.Settings.MaxCharactersInDocument; XmlNameTable nameTable = r.Settings.NameTable; ConformanceLevel cl = r.Settings.ConformanceLevel; Type t = r.Settings.GetType(); rs.Reset(); CError.Compare(cc, rs.CheckCharacters, "cc"); CError.Compare(closeinput, rs.CloseInput, "closeinput"); CError.Compare(dtd, rs.DtdProcessing, "dtd"); CError.Compare(ignorecomm, rs.IgnoreComments, "ignorecomm"); CError.Compare(ignorepi, rs.IgnoreProcessingInstructions, "ignorepi"); CError.Compare(ignorewhtsp, rs.IgnoreWhitespace, "ignorewhtsp"); CError.Compare(lineNumberOffset, rs.LineNumberOffset, "lineNumberOffset"); CError.Compare(linePositionOffset, rs.LinePositionOffset, "linePositionOffset"); CError.Compare(maxcharsindoc, rs.MaxCharactersInDocument, "maxcharsindoc"); CError.Compare(nameTable, rs.NameTable, "nameTable"); CError.Compare(cl, rs.ConformanceLevel, "cl"); CError.Compare(t, rs.GetType(), "t"); return TEST_PASS; } }