易截截图软件、单文件、免安装、纯绿色、仅160KB

jdom实现schema验证xml文件是否合法

导入jdom1.1版
http://www.jdom.org/dist/binary/
import java.io.FileReader;
import org.jdom.Document;
import org.jdom.input.SAXBuilder;
public class XMLValidate {
public void validate(String xml, String schema) {
try {
SAXBuilder builder = new SAXBuilder(true);
//指定约束方式为XML schema
builder.setFeature("http://apache.org/xml/features/validation/schema",true);
//导入schema文件
builder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",schema);
Document doc = builder.build(new FileReader(xml));
System.out.println("恭喜您,验证通过!!!");

}catch(Exception e) {
System.out.println("验证失败:"+e);
}
}

public static void main(String args[]) {
new XMLValidate().validate("e:\\a.xml","e:\\b.xsd");
}

老版本需要用到Xerces
参见http://www.jdom.org/docs/faq.html#a0360
How do I validate against a schema when using JDOM?
JDOM doesn't have it's own parser; it uses standard parsers like Xerces to do the heavy lifting. If you want schema validation make sure you choose a parser that supports schemas. Xerces 2 is a good choice (get it from http://xml.apache.org). You also need to use code JDOM Beta 8 or later.
To specify the parser JDOM uses, you can either configure JAXP appropriately (since JDOM uses JAXP if it's available, see the end of this entry for details) or you can explicitly pass the name of the parser to the SAXBuilder constructor. For Xerces 2 the parser class is org.apache.xerces.parsers.SAXParser. You must also enable parser validation by passing "true" when creating a SAXBuilder.
SAXBuilder builder =
  new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
Next, you tell the parser (Xerces) you want to validate against a schema (or schemas), and you pass the parser information about those schema. Different parsers do this in different ways. In Xerces you do this by


相关文档:

基于XML的Web分布式数据交换技术

一、WDDX的产生
    WDDX,英文全称为Web Distributed Data
Exchange,是一种基于XML的Web分布式数据交换技术。WDDX最早是美国Allaire公司的程序技术设计师Simeon
Simeonov为了解决ColdFusion中涉及到的分布计算问题而建立的。随着工作的开展,WDDX逐渐演变成为一种可用于不同的应用环境中交换复杂的结构 ......

.NET SQLServer2005 XML字段

//这是添加 
private void button1_Click(object sender, EventArgs e)
        {
            string s = "Persist Security Info=False;Integrated Security=SSPI;database=IIntegration;server=(local)";
 &n ......

java创建Xml笔记


用java创建Xml的4大类:
 
Element:节点类
Attribute属性类
Document:指的就是文档类
XMLOutput:输出类
此类是用java建立一个xml文件
 
public class TestJdom {
    //创建XML(模型)dom
    public static void main(String[] args) {
     ......

flex XML 作为数据源的实例(TESTED)

XML 作为数据源的实例(TESTED)
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" preinitialize="preInit()" fontSize="12" height="500">
        <mx:Script>
     ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号