ÓÃJDOM¶ÁÈ¡XMLÎļþ
ǰÌ᣺1.JdomµÄ¼Ü¹¹ÒѾµ¼Èë
²½Ö裺
ÓÃJDOM¶ÁÈ¡XMLÎļþÐèÏÈÓÃorg.jdom.input.SAXBuilder¶ÔÏóµÄbuild()·½·¨´´½¨Document¶ÔÏó,
È»ºóÓÃDocumentÀà¡¢ElementÀàµÈµÄ·½·¨¶ÁÈ¡ËùÐèµÄÄÚÈÝ¡£
<?xml version="1.0" encoding="UTF-8"?>
<HD>
<disk name="C">
<capacity>8G</capacity>
<directories>200</directories>
<files>1580</files>
</disk>
<disk name="D">
<capacity>10G</capacity>
<directories>500</directories>
<files>3000</files>
</disk>
</HD>
ÉÏÃæµÄsample.xmlÎĵµ£¬ÃèÊöÁËij̨µçÄÔÖÐÓ²Å̵Ļù±¾ÐÅÏ¢(¸ù½Úµã<HD>´ú±íÓ²ÅÌ£¬<disk>±êÇ©´ú±íÓ²ÅÌ·ÖÇø£¬
´ÓËüµÄnameÊôÐÔ¿ÉÒÔ¿´³öÓÐÁ½¸öÅÌ·ûÃû³ÆÎª"C"ºÍ"D"µÄ·ÖÇø£»Ã¿¸ö·ÖÇøÏ¶¼°üº¬<capacity>,<directories><files>Èý¸ö½Úµã£¬
·Ö±ð´ú±íÁË·ÖÇøµÄ¿Õ¼ä´óС¡¢Ä¿Â¼ÊýÁ¿¡¢Ëùº¬Îļþ¸öÊý)
ÏÂÃæµÄ³ÌÐò¶ÁÈ¡´ËÎļþÖеÄÐÅÏ¢£º
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("sample.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); //»ñÈ¡µÚi¸öÔªËØ
String name=element.getAttributeValue("name"); //»ñÈ¡ÊôÐÔ
String capacity=element.getChildText("capacity"); //È¡disk×ÓÔªËØcapacityµÄÄÚÈÝ
&
Ïà¹ØÎĵµ£º
CollectionÖ÷ÒªÊÇÖ¸ÏñArray, ArrayList, List, Dictionary, HashTableÕâЩÊý¾ÝÀàÐÍ£¬´ó¼ÒƽʱÓõĺܶࡣÈç¹ûÒ»¸öÀàÖÐÓÐÒ»¸öCollectionÀàÐ͵ijÉÔ±£¬ÔÚ¶ÔÕâ¸öÀà½øÐÐXMLÐòÁл¯µÄʱºò£¬Ó¦¸ÃÈçºÎ´¦Àí£¿Ó¦¸Ã˵ÔÚ.netµ±ÖÐÕâÊDZȽϼòµ¥µÄ£¬Ö»Òª½¨Á¢Ò»¸öXmlSerializerÀà¾Í¿ÉÒÔ°ïÄã×Ô¶¯¸ã¶¨£¬²»¹ýÓеÄʱºòÄã¿ÉÄÜÐèÒª¶Ô×Ô¶¯µÄÐòÁл¯¹ý³ ......
½âÎö£º
CMarkup xml;
CString strChanText, strChanType;
xml.Load("MyXml.xml");
xml.ResetMainPos();
if (!Chan.FindElem("TreeOrg"))
{
return;
}
if (xml.IntoElem())
{
xml.FindEle ......
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath(NetShop.Config.DbConfigs.GetSitePath + "images/flashdata/flash.config"));
DataRow[] drs = ds.Tables[0].Select("", "[SortOrder] ASC");
//·µ»ØµÄÊǸöDataRow[]£º
//DataR ......
antonypr | 14 April, 2007 00:05
A couple of weeks ago, I had a plan to write an article and example code of using XML parser in Symbian OS. It seems that another Forum Nokia Champion, Paul Todd had the same idea. He posted a nice article about XML parser in Symbian OS 9.x to Forum Nokia Blogs. It's ......
[Bug 230608] missing config.h in latest -14
Ralf Corsepius rc040203 at freenet.de
Tue Mar 6 13:31:13 UTC 2007
Previous message: [Bug 230608] missing config.h in latest -14
Next message: [Bug 230608] missing config.h in latest -14
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] ......