|
-
July 2nd, 2002, 06:20 AM
#1
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.
-
July 3rd, 2002, 04:45 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|