public class JAXBSource extends SAXSource
Source实现一个JAXB生成的对象。
此实用程序类将JAXB与其他Java / XML技术相结合是有用的。
以下示例显示如何使用JAXB来编组文档以进行XSLT的转换。
MyObject o = // get JAXB content tree
// jaxbContext is a JAXBContext object from which 'o' is created.
JAXBSource source = new JAXBSource( jaxbContext, o );
// set up XSLT transformation
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer(new StreamSource("test.xsl"));
// run transformation
t.transform(source,new StreamResult(System.out));
JAXBSource源自SAXSource的事实是一个实现细节。 因此,一般来说,强烈建议不要访问在SAXSource上定义的方法。 特别地,不能调用setXMLReader和setInputSource方法。 由getXMLReader方法获取的XMLReader对象只能用于解析由getInputSource方法返回的InputSource对象。
类似地,由getInputSource方法获取的InputSource对象将仅用于由getXMLReader返回的XMLReader对象进行解析。
| Constructor and Description |
|---|
JAXBSource(JAXBContext context, Object contentObject)
为给定的内容对象创建一个新的 Source 。
|
JAXBSource(Marshaller marshaller, Object contentObject)
为给定的内容对象创建一个新的 Source 。
|
getInputSource, getSystemId, getXMLReader, setInputSource, setSystemId, setXMLReader, sourceToInputSourcepublic JAXBSource(JAXBContext context, Object contentObject) throws JAXBException
Source 。
context - 用于创建contentObject 。
这个上下文用于创建一个新的marshaller实例,不能为null。
contentObject - JAXB生成的类的一个实例,将用作Source (通过将其编组为XML)。
它不能为空。
JAXBException - 如果在创建JAXBSource时遇到错误,或者如果任一参数为空。
public JAXBSource(Marshaller marshaller, Object contentObject) throws JAXBException
Source 。
marshaller - 将用于将contentObject编组为XML的编组contentObject实例。
这必须从用于构建contentObject ,并且不能为空。
contentObject - JAXB生成的类的一个实例,将用作Source (通过将其编组为XML)。
它不能为空。
JAXBException - 如果在创建JAXBSource时遇到错误,或者如果任一参数为空。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.