Jdom ¶ÁÈ¡ xmlÎļþÀý×Ó
Jdom
¶ÁÈ¡
xml
ÎļþÀý×Ó
1.
ÓÃ
JDOM
¶ÁÈ¡
XML
ÎļþÐèÏÈÓÃ
org.jdom.input.SAXBuilder
¶ÔÏóµÄ
build()
·½·¨´´½¨
Document
¶ÔÏó
,
È»ºóÓÃ
Document
Àà¡¢
Element
ÀàµÈµÄ·½·¨¶ÁÈ¡
1.
Sample1.java
import
java.util.*;
import
org.jdom.*;
import
org.jdom.input.SAXBuilder;
public
class
Sample1 {
public
static
void
main(String[] args)
throws
Exception{
SAXBuilder sb=
new
SAXBuilder();
Document doc
=sb.build(Sample1.class.getClassLoader().getResource("test.xml")); //¹¹ÔìÎĵµ¶ÔÏó
Ïó
Element root=doc
.getRootElement();
//
»ñÈ¡¸ùÔªËØ
List list=root.getChildren(
"disk"
);
//
È¡Ãû×ÖΪ
disk
µÄËùÓÐÔªËØ
for
(
int
i=0;i<list.size();i++){
Element element=(Element)list.get(i);
String name=element.getAttributeValue(
"name"
);
String capacity=element.getChildText(
"capacity"
);
//
È¡
disk
×ÓÔªËØ
capacity
µÄÄÚÈÝ
String
directories=element.getChildText(
"directories"
);
String
files
=element.getChildText(
"files"
);
System.
out
.println(
"
´ÅÅÌÐÅÏ¢
:"
);
System.
out
.println(
"
·ÖÇøÅÌ·û
:"
+name);
System.
out
.println(
"
·ÖÇøÈÝÁ¿
:"
+capacity);
System.
out
.println(
"
Ŀ¼Êý
:"
+directories);
System.
out
.println(
"
ÎļþÊý
:"
+files);
System.
out
.println(
&
Ïà¹ØÎĵµ£º
Internet µÄÓ¦ÓÃÕýÔÚ²»¶ÏµØÀ©´ó£¬µ«ÎÒÃÇµÄ Internet ±à³Ì·½Ê½»¹´¦ÓÚʯÆ÷ʱ´ú¡£Internet Óû§¾ÍÏñÀÏʽÖ÷»úµÄ·ÖʱÖÕ¶ËÉϵÄÓû§Ò»Ñù£¬ËûÃÇ´ÓÒ»¸öÊܱ£»¤µÄ×ÊÔ´ÇëÇóÐÅÏ¢£¬È»ºóµÈ´ý»ØÓ¦¡£Äã´ÓÕýÔÚä¯ÀÀµÄ Internet Õ¾µãÉϽÓÊÕµÄÐÅÏ¢ÓÉËüÏ£ÍûÌṩ¸øÄãµÄ¡¢»ùÓÚ HTML µÄÐÅÏ¢×é³ÉµÄ¡£
¡¡¡¡µ«ÊÇ£¬Í¬Ô¶³Ì Web Õ¾µã½øÐн»»¥Ê½²Ù×÷ÊDz»ÊÇ ......
Èç¹û¶Ô½çÃæÃÀ¹Û³ÌÐò±È½Ï¸ß£¬ÊÖд´úÂëÊDz»¿É±ÜÃâµÄ¡£
µ«Èç¹û×öµÄÊÇһЩÏñÖ»ÊÇΪÁËÏÔʾ¡¢¿ØÖÆÖ®ÀàµÄ³ÌÐò£¬¿ÉÄܸü¿ìµÄ°Ñ³ÌÐòµ·¹Ä³öÀ´¾ÍºÃÁË¡£
wxwidgets
ÓÐÕâÑùµÄÒ»¸ö¹¦ÄÜ£¬¾ÍÊÇÄÜÓÃxmlд³É½çÃæ¾ÍÄÜÏÔʾ
±à¼xrcµÄ¹¤¾ßÊÇwxformbuilder,¿ªÔ´Ãâ·ÑµÄ£¬Ò²×ã¹»ÓÃÁË£¬ÎÒÒ»¿ªÊ¼Ã»ÕÒµ½Ôõô
Éú³Éxrc,ºóÀ´Ä³´ÎżȻ¿´µ½ÁËÏÂÃæ....ÔÀ ......
µ½http://sourceforge.net/projects/tinyxml/ÏÂÔØTinyXmlµÄ¹Ù·½Àý×Ó£¬
ÀïÃæÓкü¸¸öÎļþ£¬ÎÒÃÇ°Ñ
tinyxml.h
tinystr.h
tinystr.cpp
tinyxml.cpp
tinyxmlparser.cpp
tinyxmlerror.cpp
Õ⼸¸öÎļþ°üº¬µ½ÎÒÃǵŤ³ÌÄÚ¡£
Òª°üº¬Í·Îļþ #include "tinyxml.h"
ÕâÓþͿÉÒÔ¿ªÊ¼Ê¹ÓÃtinyxml¿ªÊ¼²Ù×÷xmlÎļþÁË£¬¾ßÌåµÄ²Ù×÷· ......
using System;
using System.Xml;
namespace ReadXMLfromFile
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
XmlTextReader reader = new XmlTextReader ("books.xml");
......
ÔÚ XML ÖУ¬Ò»Ð©×Ö·ûÓµÓÐÌØÊâµÄÒâÒå¡£
Èç¹ûÄã°Ñ×Ö·û "<" ·ÅÔÚ XML ÔªËØÖУ¬»á·¢Éú´íÎó£¬ÕâÊÇÒòΪ½âÎöÆ÷»á°ÑËüµ±×÷ÐÂÔªËصĿªÊ¼¡£
ÕâÑù»á²úÉú XML ´íÎó£º
<message>if salary < 1000 then</message>
ΪÁ˱ÜÃâÕâ¸ö´íÎó£¬ÓÃÒ»¸öʵÌåÒýÓÃÀ´´úÌæ "<" ×Ö·û£º
<message>if salary < 1000 then ......