DOM4J¶ÔXMLÎĵµµÄ¶ÁдÔöɾ¸ÄµÈ
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class MyTest {
Document doc = null;
public MyTest() throws DocumentException, IOException, SAXException {
Document doc = loadXML("class.xml"); // ÔØÈëXMLÎĵµ
System.out.println(doc.asXML());
printDoc(doc); // ´òÓ¡XMLÎĵµ
storeDoc(doc, "new.xml"); // °ÑXMLÎĵµ´æÈëÓ²ÅÌ
doc = valideDoc("class.xml"); // УÑédtd XMLÎĵµ
printDoc(doc);
doc = validateDocBySxd("classSchema.xml"); // УÑéSchemaÎĵµ
printDoc(doc);
String url = getClass().getResource("/xml/dom4j/wkjava/class.xsd").toString();
doc = validateDocBySxd("classSchema.xml", url); // УÑéSchemaÎĵµ£¨Á©²ÎÊý£©
printDoc(doc);
doc = createDoc(); // ´´½¨SchemaÎĵµ
storeDoc(doc, "root.xml");
doc = validateDocBySxd("classSchema.xml");
updateZip(doc, "102202"); // ÔÚÎĵµÖÐÐÞ¸ÄÔÊô
printDoc(doc);
doc = validateDocBySxd("classSchema.xml");
printNames(doc); // ´òÓ¡ÎĵµÖÐËùÓÐѧÉúÃû×Ö
System.out.println(getStudentCount(doc));
}
public static void main(String[] args) {
try {
ne
Ïà¹ØÎĵµ£º
ÒÔÏÂÊÇÒ»¸öͨ¹ýminidomÄ£¿éдÎļþµÄÍêÕûʾÀý£¬ÊÇÔÚ×î½ü×öµÄÏîÄ¿WalleÉÏÃæÓõ½µÄ,Õâ¸öʾÀýµÄÄ¿µÄÊÇÉú³ÉÒ»¸öÈçϵĸñʽµÄxml£¬Îļþ¸ñʽΪÎÞBOM utf-8¡£
Éú³ÉxmlÎļþ¸ñʽ£º
<?xml version="1.0" encoding="utf-8"?>
<coverages>
<coverage>
  ......
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class XMLReader {
public static List ......
ÔÚÓÃXML±£´æÒ»¸öĬÈϵĶ«Î÷µÄʱºò£¬ÎÒÔÚloadformµÄʱºòÓÃxmltextreaderÀà¶ÁÈ¡ÁËxmlÎļþ µ«ÊÇÔÚÆäËûµØ·½ÔÙ¶ÔÕâ¸öxmlÎļþ²Ù×÷µÄʱºò¾Í³öÏÖÎÊÌâÁË ÊÇ˵Ï̵߳ÄÎÊÌâ ËùÒÔÐèÒªÏȹصôÕâ¸öÎļþ ÓõÄÊÇxmltextreaderµÄclose·½·¨ msdn²éµ½µÄ¡£ ......
C#¶ÁÈ¡XML×ÊÁÏ
Ò» C#¶ÁÈ¡XML×ÊÁÏ
À©³ä±ê¼ÇÓïÑÔXML£¨eXtensible Markup Language£©£¬ÊÇÓÉWÈýC»ú¹ØÖƶ©µÄ¡£×öΪÓÃÒÔ´úÌæHTMLÓïÑÔµÄÒ»ÖÖÐÂʽµÄ±ê¼ÇÓïÑÔ£¬XMLÄÚ²¿ÓÐןܶà¸ù±¾»ù×¼£¬XMLÄËÊǾ¹ýÓëÕâЩÏà¸É»ù×¼µØ×éºÏ£¬Ó¦ÓÃÓÚ¿Æѧ¼ÆËã¡¢µç×Ó³ö°æ¡¢¶àýÌåϵÌåÀý×÷ºÍµç×ÓÉÌÎñµÄ¡£C££×÷ΪһÖÖÐÂʽµÄ³ÌÐòÓïÑÔ£¬ÊÇ.Net¹¹¼ÜµÄÒ»¸öÖ ......
Õâ¸ö¶«Î÷¹¦Äܼܺòµ¥£¬Ã»ÓÐʲô¼¼Êõº¬Á¿¡£Ö»ÊǼǼһÏ¡£
xml µÄÊý¾Ý»ñÈ¡ºó£¬¿ÉÒÔͨ¹ýÒ»¸ö¼òµ¥·ÖÒ³´¦ÀíÀ´Íê³É¼òµ¥·ÖҳЧ¹û¡£
1.ÀûÓÃÇóÓàºÍ³ý·¨µÄ·½·¨ÅжÏÒ³Êý
Õâ¸öÊÇÒ»¸ö±È½Ï³£¼ûµÄ×ö·¨£¬Ò²ÊÇÒ»ÖÖ°ì·¨¡£ÔÚÕâÀ²»¶ÔÕâÖÖ·ÖÒ³´¦ÀíÒª´ïµ½Ê²Ã´×îÓÅ»¯µÄЧ¹û½øÐÐÌÖÂÛ£¬ÕâÀïÖ»ÊÇ̽ÌÖÒ»ÖÖ°ì·¨¡£¶ÔһР......