CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: sax parser

  1. #1
    Join Date
    May 2002
    Location
    Hyderabad,India.
    Posts
    27

    sax parser

    haloo,

    i want an url for java sax2.0 parser with
    documentation to download. And please
    give a small program to read xml file
    using that parser.

    thanks.

  2. #2
    Join Date
    Aug 2001
    Location
    Russia, Moscow
    Posts
    26
    Hi
    xerces is XML parser
    xalan is XSLT engine

    http://wwws.sun.com/software/xml/dev...redirect=false

    http://wwws.sun.com/software/xml/dev...redirect=false

    ------------------------------------
    My sample is in Jython, but I hope you easily understand what to do.
    ------------------------------------
    from javax.xml.parsers import DocumentBuilderFactory

    dFactory = DocumentBuilderFactory.newInstance()
    dFactory.setNamespaceAware(1)
    dBuilder = dFactory.newDocumentBuilder()

    # New empty DOM
    emptyXML = dBuilder.newDocument()

    # parse URL or file
    xml = dBuilder.parse(file_Or_Url_Name)

    # parse stream
    xml = dBuilder.parse(stream)

    # parse string
    sStream = ByteArrayInputStream(str.encode('UTF-8'))
    xml = dBuilder.parse(sStream)

    # node to text
    from org.apache.xalan.serialize import SerializerToXML
    serializer = SerializerToXML()
    s = ByteArrayOutputStream()
    serializer.setOutputStream( s )
    serializer.serialize( xmlNode )
    text = s.toString('UTF-8')

    # selectNodes
    from org.apache.xpath import XPathAPI
    nodeList = XPathAPI.selectNodeList(contextNode, xpath)

    # selectSingleNode
    node = XPathAPI.selectSingleNode(contextNode, xpath)

    # transformNodeToObject (srcNode - source , xslNode - xsl style)
    from org.apache.xalan.processor import TransformerFactoryImpl
    from javax.xml.transform.dom import DOMSource
    from javax.xml.transform.dom import DOMResult
    transformerFactory = TransformerFactoryImpl()
    sourceXSL = DOMSource(xslNode)
    transformer = transformerFactory.newTransformer(sourceXSL)
    source = DOMSource(srcNode)
    trgNode = dBuilder.newDocument()
    result = DOMResult(trgNode)
    transformer.transform(source, result)
    # trgNode is transformation result
    Denis.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured