GenXDM是非常著名的中间件软件厂商TIBCO公司贡献一个出来XML的一个非常灵活和强大的开源框架(基于Apache的License),其提供了一套机制和接口,把所有的DOM的操作和解析模型通过一种统一的方式来实现。因此,GenXDM框架本身提供了AxiomProcessingContext,DomProcessingContext和XmlNodeContext的一套处理机制。其实GenXDM本身只是一个壳子,必选由相应的Axiom,Dom或者XmlNode的配合起来,才能进行XML文件的create,update和Read。大家可以从下面的地址去下载其源代码:http://www.genxdm.org/source-repository.html
最后给大家一个简单的例子,通过GenXDM生成一个XML数据,非常的灵活和简单,可以还可以兼容不同的XML的实现的框架。希望能对大家起到抛砖引玉的作用。
import java.util.Iterator; import org.genxdm.ProcessingContext; import org.genxdm.io.FragmentBuilder; import com.tibco.genxdm.bridge.xinode.XiProcessingContext; import com.tibco.xml.datamodel.XiNode; public class CreateDom { public static void main(String[] args) throws Exception { ProcessingContext<XiNode> context = new XiProcessingContext(); FragmentBuilder<XiNode> builder = context.newFragmentBuilder(); /* * <? xml version="1.0" encoding="UTF-8"?> <!--comment--> <?pi data?> <element xmlns ="http://localhost" attr ="value">text</element> */ final String LF = "\n" ; builder.startDocument( null , null ); builder.text(LF); builder.comment( "comment" ); builder.text(LF); builder.processingInstruction( "pi" , "data" ); builder.startElement( "http://localhost" , "element" , "" ); builder.namespace( "" , " http://localhost " ); builder.attribute( "" , "attr" , "" , "value" , null ); builder.text( "text" ); builder.endElement(); builder.endDocument(); XiNode doc = builder.getNode(); System. out .println(doc); System. out .println( "++++++++++++++=====" ); System. out .println( "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq" ); String str=com.tibco.xml.datamodel.helpers.XiSerializer. serialize (doc); System. out .println(str); System. out .println( "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq" ); Iterable<XiNode> ns = context.getModel().getChildElements(doc); Iterator<XiNode> iter = ns.iterator(); while (iter.hasNext()) { XiNode n = iter.next(); System. out .println(context.getModel().getLocalName(n)); } } }
另外,大家可以到下面的地址的去下载参考书籍,写的非常的好。
http://www.genxdm.org/book/index.html
时间: 2024-10-15 14:19:24