利用VC++实现对XML结点的更新和追加
实现功能:根据配置文件(XXXX.ini)中的内容对XML中节点进行操作,如果XML中存在与配置文件中相同的节点,则根据配置文件将XML文件中相应节点的值进行更新;如果XML文件中不存在配置文件中出现的节点,则在XML中将新节点及值进行插入操作。
◆XML文档结构如下
//--------------------------------------------------------------------------------------------
- <printer driver-name="OKI C710(PS)">
<color-profile path="ColorProfiles/OkiC710CMY.icc" />
</printer>
- <printer driver-name="OKI C710(PCL)">
<color-profile path="ColorProfiles/OkiC710CMY.icc" />
</printer>
- <printer driver-name="OKI C830(PS)">
<color-profile path="ColorProfiles/OkiC830CMY_new.icc
" />
</printer>
- <printer driver-name="OKI C830(PCL)">
<color-profile path="ColorProfiles/OkiC830CMY.icc" />
</printer>
//--------------------------------------------------------------------------------------------
◆配置文件结构如下
//----------------------------------------------------------------------------------------------
[Driver]
D1=OKI C830(PCL);OkiC830CMY_new;ColorProfiles/OkiC830CMY_new.icc
D2=OKI C810(PCL);OkiC810CMY_new;ColorProfiles/OkiC810CMY_new.icc
//-----------------------------------------------------------------------------------------------
实现步骤:
1, 读取配置文件,并将其中的信息内容用类对像进行保存
2, 对XML档进行更新.
因为整个过程并不复杂,现将代码附上。
类定义
//CCustomMediaInfoクラスの定義
//機能:GridLayouter機種設定ツールのGLPDFInfo.datファイル情報を初期化処理
//期日:2009.10.29
//作成:
//その他:The CustomMedia.ini file is located at ..\CustomMedia\CustomMediaInfo.ini
#define MAX_UPDATE_PRN 256 //The must number of printers to be updated.
//To save the value of every item of a line in GLPDFInfo.dat or okPrnInfo
相关文档:
已知有一个XML文件(bookstore.xml)如下:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price> ......
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
(1)使用JDOM首先要指定使用什么解析器。如:
SAXBuilder builder=new SAXBuilder(false) ......
2009-12-19考了CET英语,心情很差,估计又不过的,哎!英文差!
于是看看书,看看自己感兴趣的书
今天下午,研究了整个下午的小难题,在8点40分终于搞定了!肚子饿,还没吃饭,还没洗澡,克服了一个不懂的小难题,心理有点体会,想在这里留点纪念,方便别人以后学习。于是乎,我写了:
(那些开训练器的相关介绍我就不再 ......
原贴:http://topic.csdn.net/u/20100412/14/f6941844-e9bf-4ed7-a0c2-bef03d775783.html?70615
declare @data xml=
'<root>
<SaleMan>
<SaleManId>1</SaleManId>
<SaleManCode>001</SaleManCode>
<Nodes>
<Node>
< ......