[Home] [By Thread] [By Date] [Recent Entries]



> Could you please share sample coding how to read a file into SAX.NET?

Sure, here it is (from memory, not tested):

IXMLReader reader = new KDS.Xml.Expat.ExpatReader();
// or if a default parser is configured:
// IXMLReader reader = SAXReaderFactory.CreateReader(null); 
FileStream fileStm = new FileStream(myFileName, FileMode.Open, FileAccess.Read);

// maybe turn namespaces on
reader.SetFeature(System.Xml.Sax.Constants.namespacesFeature, true);
// set call-back handlers
reader.ErrorHandler = myErrorHandler;
reader.ContentHandler = myContenthandler;
IProperty declProp = reader.GetProperty(
              System.Xml.Sax.Constants.declHandlerProperty);
declProp.Value = myDeclhandler;
IProperty lexProp = reader.GetProperty(
              System.Xml.Sax.Constants.lexicalHandlerProperty);
lexProp.Value = myLexicalhandler;
// process the file
try {
  reader.Parse(new StreamInputSource(fileStm));
}
finally {
   fileStm.Close();
}


Karl

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member