Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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


Ïà¹ØÎĵµ£º

Whitespace is not allowed before an XML Processing

ת£ºhttp://hi.baidu.com/oneshotonekill/blog/item/be68b513f7c929d7f6039e1e.html
Whitespace is not allowed before an XML Processing Instruction (< ? ... ?>). HTMLComponent.EclipseÔڱ༭mxmlµÄʱºòÌáʾÕâÑùµÄ´íÎó¡£¼ì²é²Å·¢ÏÖ´úÂëÖÐÔÚ<? ?>֮ǰ´æÔÚ¿Õ¸ñ¡£ ......

SQL 2005ÖÐÓÃXML nodes()º¯ÊýÈ¡´úOPENXML

SQL Server 2005ΪXMLÌṩ±¾µØÖ§³Ö;ÏÖÔÚ¿ÉÒÔÔÚOPENXML½ÚµãÖÐʹÓÃÒ»¸ö´øÓÐnodes()º¯ÊýµÄXML×Ö¶ÎÀàÐÍ°ÑÒ»¸öXMLÎļþת»¯ÎªÒ»¸öÐм¯¡£ÈÃÎÒÃÇÀ´¿´Ò»¸öʹÓÃOPENXMLµÄ¼òµ¥Àý×Ó£¬²¢ÏÔʾÈçºÎ°ÑËüת»¯ÎªÔÚSQL Server 2005ÖÐʹÓÃXML×Ö¶ÎÀàÐͺÍnodes()º¯Êý¡£
¡¡¡¡ÎªÁËʹÎÒÃǵÄÀý×Ó¼òµ¥»¯£¬ÎÒÃǽ«¼ÙÉèÎÒÃÇÐèÒªÖ´ÐÐijÖÖ»ùÓڲɹº¶©µ¥ÁÐ±íµ ......

DOMÓëSAX½âÎöxmlµÄÇø±ð


SAX¸ÅÄî
SAXÊÇSimple API for XMLµÄËõд£¬Ëü²¢²»ÊÇÓÉW3C¹Ù·½ËùÌá³öµÄ±ê×¼£¬¿ÉÒÔ˵ÊÇ“Ãñ¼ä”µÄÊÂʵ±ê×¼¡£Êµ¼ÊÉÏ£¬ËüÊÇÒ»ÖÖÉçÇøÐÔÖʵÄÌÖÂÛ²úÎï¡£ËäÈ»Èç´Ë£¬ÔÚXMLÖжÔSAXµÄÓ¦ÓÃË¿ºÁ²»±ÈDOMÉÙ£¬¼¸ºõËùÓеÄXML½âÎöÆ÷¶¼»áÖ§³ÖËü¡£
ÓëDOM±È½Ï¶øÑÔ£¬SAXÊÇÒ»ÖÖÇáÁ¿Ð͵ķ½·¨¡£ÎÒÃÇÖªµÀ£¬ÔÚ´¦ÀíDOMµÄʱºò£¬ÎÒÃÇÐèÒª¶Á ......

java´´½¨Xml±Ê¼Ç


ÓÃjava´´½¨XmlµÄ4´óÀࣺ
 
Element£º½ÚµãÀà
AttributeÊôÐÔÀà
Document£ºÖ¸µÄ¾ÍÊÇÎĵµÀà
XMLOutput£ºÊä³öÀà
´ËÀàÊÇÓÃjava½¨Á¢Ò»¸öxmlÎļþ
 
public class TestJdom {
    //´´½¨XML£¨Ä£ÐÍ£©dom
    public static void main(String[] args) {
     ......

XML¸ñʽת»¯¹¤¾ßÀà

»ùÓÚdom4jµÄXML¸ñʽת»¯Àà
package com.lixi.util;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import org.dom4j.Document;
import org.do ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ