XML×Ö·û´®ºÍXML DOCUMENTµÄÏ໥ת»»¡¾×ª¡¿
ÔÚ×öÒ»°ãµÄXMLÊý¾Ý½»»»¹ý³ÌÖУ¬ÎÒ¸üÀÖÒâ´«µÝXML×Ö·û´®£¬¶ø²»ÊǸñʽ»¯µÄXML Document¡£Õâ¾ÍÉæ¼°µ½XML×Ö·û´®ºÍXml DocumentµÄת»»ÎÊÌ⣬˵°×ÁËÕâÊǸöºÜ¼òµ¥µÄÎÊÌ⣬±¾Îľ͸÷ÖÖXML½âÎöÆ÷·Ö±ðÁоÙÈçÏ£¬ÒÔ·½±ã×Ô¼º½ñºó²éÔÄ¡£
Ò»¡¢Ê¹ÓÃ×îÔʼµÄjavax.xml.parsers£¬±ê×¼µÄjdk api
// ×Ö·û´®×ªXML
String xmlStr = "......";
StringReader sr = new StringReader(xmlStr);
InputSource is = new InputSource(sr);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
Document doc = builder.parse(is);
//XMLת×Ö·û´®
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
t.setOutputProperty("encoding","GB23121");//½â¾öÖÐÎÄÎÊÌ⣬ÊÔ¹ýÓÃGBK²»ÐÐ
ByteArrayOutputStream bos = new ByteArrayOutputStream();
t.transform(new DOMSource(doc), new StreamResult(bos));
String xmlStr = bos.toString();
ÕâÀïµÄXML DOCUMENTΪorg.w3c.dom.Document
¡¡¡¡¶þ¡¢Ê¹ÓÃdom4jºó³ÌÐò±äµÃ¸ü¼òµ¥
// ×Ö·û´®×ªXML
String xmlStr = "......";
Document document = DocumentHelper.parseText(xmlStr);
// XMLת×Ö·û´®
Document document = ...;
String text = document.asXML();
ÕâÀïµÄXML DOCUMENTΪorg.dom4j.Document
¡¡¡¡Èý¡¢Ê¹ÓÃJDOM
JDOMµÄ´¦Àí·½Ê½ºÍµÚÒ»ÖÖ·½·¨´¦Àí·Ç³£ÀàËÆ
//×Ö·û´®×ªXML
String xmlStr = ".....";
StringReader sr = new StringReader(xmlStr);
InputSource is = new InputSource(sr);
Document doc = (new SAXBuilder()).build(is);
//XMLת×Ö·û´®
Format format = Format.getPrettyFormat();
format.setEncoding("gb2312");//ÉèÖÃxmlÎļþµÄ×Ö·ûΪgb2312£¬½â¾öÖÐÎÄÎÊÌâ
XMLOutputter xmlout = new XMLOutputter(format);
ByteArrayOutputStream bo = new ByteArrayOutputStream();
xmlout.output(doc,bo);
String xmlStr = bo.toString();
ÕâÀïµÄXML DOCUMENTΪorg.jdom.Document
¡¡¡¡ËÄ¡¢JAVASCRIPTÖеĴ¦Àí
//×Ö·û´®×ªXML
var xmlStr = ".....";
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.loadXML(xmlStr);
//¿ÉÒÔ´¦ÀíÕâ¸öxmlDocÁË
var name = xmlDoc.selectSingleNode("/person/name");
alert(name.text);
//XML
Ïà¹ØÎĵµ£º
ArrayCollectionת³ÉxmlÀàÐÍʾÀý
ÏÂÃæÄ£ÄâÒ»×éÊý¾Ýexams,½«Æäת»¯ÎªxmlÐÎʽ.Ïêϸ´úÂë¼ûÏ£º
Xml´úÂë
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12" creationComplet ......
ÏÂÎç¿´ÁËÒ»ÏÂdomºÍdom4j£¬¸Ð¾õÕâÁ½ÕßÔÚ½âÎö·½Ãæ²î²»¶à£¬µ«ÊÇdom4jÒª±Èdom¼òµ¥Ò»Ð©£¬ÔÚ´´½¨Ò»¸öxmlÎļþ£¬dom4jÒª±Èdom¼òµ¥Ì«¶àÁË£¬±Ï¾¹È˼Ҷ¼°ïÎÒÃÇ·â×°ºÃÁË¡£
domÊDz»ÐèÒª¼Ó°üµÄ£¬¶ødom4jÒª¼ÓÒ»¸ödom4j-1.6.1.jarÕâ¸ö°ü¡£¾ßÌåµÄÏÂÔØ·¾¶ÊÇ£ºhttp://www.dom4j.org/
ÏÂÃæÎÒ˵һÏÂÕâÁ½ÕßÈçºÎ½âÎöºÍ´´½¨£¬ÒÔ¼°ËûÃǵÄÇø±ð¡£x ......
XML DTD ÈëÃÅ(2009-12-14 09:08:49)
±êÇ©£ºÔÓ̸
DTDʵ¼ÊÉÏ¿ÉÒÔ¿´×÷Ò»¸ö»ò¶à¸öXMLÎļþµÄÄ£°å£¬ÕâЩXMLÎļþÖеÄÔªËØ¡¢ÔªËصÄÊôÐÔ¡¢ÔªËصÄÅÅÁз½Ê½/˳Ðò¡¢ÔªËØÄܹ»°üº¬µÄÄÚÈݵȣ¬¶¼±ØÐë·ûºÏDTDÖеĶ¨Òå¡£XMLÎļþÖеÄÔªËØ£¬¼´ÎÒÃÇËù´´½¨µÄ±ê¼Ç£¬ÊǸù¾ÝÎÒÃÇÓ ......
XmlDocument XMLFile = new XmlDocument();
XMLFile.Load(HttpContext.Cur ......
xmlÎļþ
£¼?xml version="1.0" encoding="GB2312"?£¾
£¼RESULT£¾
£¼VALUE£¾
¡¡¡¡ £¼NO£¾A1234£¼/NO£¾
¡¡¡¡ £¼ADDR£¾ËÄ´¨Ê¡XXÏØXXÕòXX·X¶ÎXXºÅ£¼/ADDR£¾
£¼/VALUE£¾
£¼VALUE£¾
¡¡¡¡ £¼NO£¾B1234£¼/NO£¾
¡¡ ¡¡£¼ADDR£¾ËÄ´¨Ê¡XXÊÐXXÏçXX´åXX×飼/ADDR£¾
£¼/VALUE£¾
£¼/RESULT£¾
ÐèҪʲô°ü×Ô¼ºµ½ÍøÉÏ ......