You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Jon Smirl <jo...@mediaone.net> on 2000/08/10 04:19:14 UTC

SAX XPCOM wrapper

I've built a scriptable XPCOM SAX wrapper for the Apache Xerces XML parser.
I decided to change my strategy on how I'm integrating Xerces into my
project and now I don't need the component anymore. What should I do with
the source code? I don't think I should just delete it. It's currently a
MSVC 6 project but it doesn't use any windows APIs so it should be platform
portable. It's 3,787 lines of code.

I've also built the IDL and wrapper files for SAX2 support but Xerces' SAX2
support isn't ready yet. It will take about two day's work to hook up SAX2
when Xerces is ready. The needed code can be easily copied from the SAX
implementation.

This code was designed for use with standalone XPCOM and Javascript. It will
take a small amount of work to make it safe for use in the browser. XPCOM
is Mozilla's cross platform version of Microsoft's COM.

New strategy is based on XMLDocument instead of SAX.

--
Jon Smirl
jonsmirl@mediaone.net

Sample Javascript code using the component..............

function InputSource() {}

InputSource.prototype = {
 getPublicId: function() {return this.publicId;},
  getSystemId: function() {return this.systemId;},
 getEncoding: function() {return this.encoding;},
 getByteStream: function() {return this.byteStream;},
}

var cParser = Components.classes["sax.Parser"];
var parser = cParser.createInstance(Components.interfaces.saxIParser);

var cHandlerBase = Components.classes["sax.HandlerBase"];
var HandlerBase =
cHandlerBase.createInstance(Components.interfaces.nsISupports);
var EntityResolver =
HandlerBase.QueryInterface(Components.interfaces.saxIEntityResolver);
var DTDHandler =
HandlerBase.QueryInterface(Components.interfaces.saxIDTDHandler);
var ErrorHandler =
HandlerBase.QueryInterface(Components.interfaces.saxIErrorHandler);

parser.setEntityResolver(EntityResolver);
parser.setDTDHandler(DTDHandler);
parser.setErrorHandler(ErrorHandler);

inputSource = new InputSource();

var cFileSpec = Components.classes["component://netscape/filespec"];
var FileSpec = cFileSpec.createInstance(Components.interfaces.nsIFileSpec);
FileSpec.URLString = "file:///D|/xpl/cCustJob.xml"
FileSpec.openStreamForReading();
inputSource.byteStream = FileSpec.inputStream;

function DocumentHandler() {}

DocumentHandler.prototype = {
 characters: function(charData) {print("charData: "+charData);},
  endDocument: function() {print("EndDocument");},
  endElement: function(name) {print("endElement: "+name);},
  ignorableWhitespace: function(charData) {print("charData: "+charData);},
  processingInstruction: function(target, data) {print("PI: "+target+" Data:
"+data);},
  setDocumentLocator: function(locator) {print("Locator: "+locator);},
  startDocument: function() {print("StartDocument");},
  startElement: function(name, atts) {
  print("StartElement: "+name);
  for (i = 0; i < atts.getLength(); i++)
   print("  Name: "+atts.getName(i)+" Value: "+atts.getValue(i));
 }
};

documentHandler = new DocumentHandler();
parser.setDocumentHandler(documentHandler);

parser.parseInputSource(inputSource);





Re: SAX XPCOM wrapper

Posted by Jon Smirl <jo...@mediaone.net>.
> Would this allow someone to take Xerces and Mozilla's JavaScript engine
and
> integrate it with their application? If so, I'd be interested in it.

That was the purpose of it.

Is there enough interest that we should add it to the tree?

Jon Smirl
jonsmirl@mediaone.net


RE: SAX XPCOM wrapper

Posted by "David E. Cleary" <da...@progress.com>.
> This code was designed for use with standalone XPCOM and
> Javascript. It will
> take a small amount of work to make it safe for use in the browser. XPCOM
> is Mozilla's cross platform version of Microsoft's COM.

Would this allow someone to take Xerces and Mozilla's JavaScript engine and
integrate it with their application? If so, I'd be interested in it.

David Cleary
Progress Software