jaxp

Make JAXB go faster

风流意气都作罢 提交于 2019-12-02 17:43:28
I have a 8 Meg file. Marshalling using JAXB takes 1082ms, using DOM takes 862ms, using SAX takes 438ms. This is using all defaults with JDK 1.6, no extra configuration such as using woodstox is used. In an effort, to get better performance from JAXB, I try to make it use SAX parsing by doing... FileReader fr = new FileReader("myfile.xml"); JAXBContext jc = JAXBContext.newInstance(MyObjectList.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); XMLInputFactory xmlif = XMLInputFactory.newInstance(); XMLEventReader xmler = xmlif.createXMLEventReader(fr); long beginTime = System

Resolving which version of an XML Schema to use for XML documents with a version attribute

落花浮王杯 提交于 2019-12-02 10:59:28
问题 I have to write some code to handle reading and validating XML documents that use a version attribute in their root element to declare a version number, like this: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <Junk xmlns="urn:com:initech:tps" xmlns:xsi="http://www3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:com:initech.tps:schemas/foo/Junk.xsd" VersionAttribute="2.0"> There are a bunch of nested schemas, my code has an org.w3c.dom.ls.LsResourceResolver to figure out what

XSL left-right justification with Padding

核能气质少年 提交于 2019-12-01 06:54:54
问题 Is there any standard template in XSLT 1.0 available which does justification and pad the field to max length? Thanks, Prabhjot 回答1: Unfortunately XSLT does not comes with the padding function, the good part is that is very simple to do so as pointed by this blog post: http://www.dpawson.co.uk/xsl/sect2/padding.html. For example if you want to right pad a 10 spaces string you can do: <xsl:value-of select="substring(concat($string, ' '), 1, 10))"/> if you need a left pad you can change the

Java (JAXP) XML parsing differences of DocumentBuilder

好久不见. 提交于 2019-12-01 01:47:24
问题 Is there any kind of difference between DocumentBuilder.parse(InputStream) and DocumentBuilder.parse(InputSource) ? I could only find that for the first case, the parser detects the encoding from the stream so it is safer while in the latter I am not sure if it is required to set the encoding. Any other points (e.g. performance) I should be aware? 回答1: The main difference is that the first one allows you to read your XML content only from binary sources, based on the implementations of the

How to Fool the Java Service Provider API (jaxp)

主宰稳场 提交于 2019-11-30 22:21:36
I have an applet that needs to call JAXP, specifically SAXParserFactory . Now, as you can see from the Javadoc, this internally uses the Service Provider mechanism as documented here : Specifically, if it does not find a file in any of my application JARs called META-INF/services/javax.xml.parsers.SAXParserFactory it will try to fetch it from my application codebase. If I have my applet deployed as follows: <applet code="com.example.applets.MyApplet" codebase="http://www.example.com/myapp/" archive="myapp.jar, dom4j.jar"> Then it will try to make an HTTP request to http://www.example.com/myapp

How to Fool the Java Service Provider API (jaxp)

我的梦境 提交于 2019-11-30 17:55:15
问题 I have an applet that needs to call JAXP, specifically SAXParserFactory. Now, as you can see from the Javadoc, this internally uses the Service Provider mechanism as documented here: Specifically, if it does not find a file in any of my application JARs called META-INF/services/javax.xml.parsers.SAXParserFactory it will try to fetch it from my application codebase. If I have my applet deployed as follows: <applet code="com.example.applets.MyApplet" codebase="http://www.example.com/myapp/"

How to validate an XML document using a RELAX NG schema and JAXP?

有些话、适合烂在心里 提交于 2019-11-30 08:34:52
I would like to validate XML documents using RELAX NG schemata, and I would like to use the JAXP validation API . From Googling around, it appeared that I could use Jing and the ISO RELAX JARV to JAXP Bridge . Unfortunately, after adding both to my classpath, I can't get it to work. SchemaFactory is just throwing an IllegalArgumentException as soon as it tries to instantiate a factory — I looked inside SchemaFactory , apparently SchemaFactoryFinder is returning a null result. So I'd appreciate answers to either question: How can I make this work with Jing and this bridge? Is there a better

Java and XML (JAXP) - What about caching and thread-safety?

三世轮回 提交于 2019-11-30 00:43:40
I'd like to know which objects can be reused (in the same or different document) when using the Java API for XML processing, JAXP: DocumentBuilderFactory DocumentBuilder XPath Node ErrorHandler (EDIT: I forgot that this has to be implemented in my own code, sorry) Is it recommended to cache those objects or do the JAXP implementations already cache them? Is the (re)use of those objects thread-safe ? bdoughan Reuse In the same thread those objects can and should be reused. For example you can use the DocumentBuilder to parse multiple documents. Thread Safety DocumentBuilderFactory used to

xml的2种解析方式(DOM和SAX解析方式)

纵然是瞬间 提交于 2019-11-29 06:03:57
1、xml的解析的简介(*****) * dom和sax区别 ==================================================================== 1、xml的解析的简介(写到java代码)(***今天最重要的内容*****) * xml是标记型文档 * js使用dom解析标记型文档? - 根据html的层级结构,在内存中分配一个树形结构,把html的标签,属性和文本都封装成对象 - document对象、element对象、属性对象、文本对象、Node节点对象 * xml的解析方式(技术):dom 和 sax ** 画图分析使用dom和sax解析xml过程 *** dom解析和sax解析区别: ** dom方式解析 - 根据xml的层级结构在内存中分配一个树形结构,把xml的标签,属性和文本都封装成对象 * 优点:很方便实现增删改操作 * 缺点:如果文件过大,造成内存溢出 ** sax方式解析 - 采用事件驱动,边读边解析,从上到下,一行一行的解析,解析到某一个对象,返回对象名称, 当SAX解析结束,不会保存任何XML文档的数据。 * 优点:如果文件过大,不会造成内存溢出,方便实现查询操作 * 缺点:不能实现增删改操作 * 想要解析xml,首先需要的解析器 ** 不同的公司和组织提供了 针对dom和sax方式的解析器

Java and XML (JAXP) - What about caching and thread-safety?

↘锁芯ラ 提交于 2019-11-28 21:41:31
问题 I'd like to know which objects can be reused (in the same or different document) when using the Java API for XML processing, JAXP: DocumentBuilderFactory DocumentBuilder XPath Node ErrorHandler (EDIT: I forgot that this has to be implemented in my own code, sorry) Is it recommended to cache those objects or do the JAXP implementations already cache them? Is the (re)use of those objects thread-safe ? 回答1: Reuse In the same thread those objects can and should be reused. For example you can use