VB6.0如何读取并修改XML文件?
你有两个选择:
1、将xml文件当做文本文件来处理。替换指定字符即可。
2、使用 MSXML 组件来处理。度娘搜一下,一大堆文档可参考。
打字不易,如满意,望采纳。
import javaioFile;
import javaxxmlparsersDocumentBuilder;
import javaxxmlparsersDocumentBuilderFactory;
import orgw3cdomDocument;
import orgw3cdomElement;
import orgw3cdomNodeList;
public class Xml {
public static void main(String[] args) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory
newInstance();
DocumentBuilder builder = factorynewDocumentBuilder();
Document document = builderparse(new File("E:\\新建 文本文档 (3)xml"));
Element rootElement = documentgetDocumentElement();
NodeList list = rootElementgetElementsByTagName("Header");
Element element = (Element) listitem(0);
Systemoutprintln(elementgetChildNodes()item(0)getNodeValue());
} catch (Exception e) {
Systemoutprintln("exception:" + egetMessage());
}
}
}
我项目里面用到的,第一个是读取,下面一个是写入和更改。
protected void BindSetting()
{
DataSet ds = new DataSet();
dsReadXml(ServerMapPath("~/Setting/Score_Settingsxml"));
DataRow dr = dsTables["Setting"]Rows[0];
TextBoxRegScoreText = dr["RegScore"]ToString();
TextBoxPerfectScoreText = dr["PerfectScore"]ToString();
TextBoxMemberCardScoreText = dr["MemberCardScore"]ToString();
TextBoxDevelopMemberScoreText = dr["DevelopMemberScore"]ToString();
TextBoxShopScoreText = dr["ShopScore"]ToString();
TextBoxSendScoreText = dr["SendScore"]ToString();
TextBoxGroupBuyActivityScoreText = dr["GroupBuyActivityScore"]ToString();
TextBoxBirthdayScoreText = dr["BirthdayScore"]ToString();
TextBoxFeastScoreText = dr["FeastScore"]ToString();
}
protected void ButtonEdit_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
dsReadXml(ServerMapPath("~/Setting/Score_Settingsxml"));
DataRow dr = dsTables["Setting"]Rows[0];
dr["RegScore"] = TextBoxRegScoreText;
dr["PerfectScore"] = TextBoxPerfectScoreText;
dr["MemberCardScore"] = TextBoxMemberCardScoreText;
dr["DevelopMemberScore"] = TextBoxDevelopMemberScoreText;
dr["ShopScore"] = TextBoxShopScoreText;
dr["SendScore"] = TextBoxSendScoreText;
dr["GroupBuyActivityScore"] = TextBoxGroupBuyActivityScoreText;
dr["BirthdayScore"] = TextBoxBirthdayScoreText;
dr["FeastScore"] = TextBoxFeastScoreText;
dsWriteXml(ServerMapPath("~/Setting/Score_Settingsxml"));
dsAcceptChanges();
}
0条评论