易截截图软件、单文件、免安装、纯绿色、仅160KB

VC读写XML文件


今天对XML文件进行了一些简单的读写操作,下面来具体实现步骤:
首先:建立一个基于Dialog的MFC工程,工程名为OperateXML,然后在对话框上添加两个按钮("Create"和"GetData"和一个ListControl
控件(用来显示数据),首先要导入库文件
#import "msxml3.dll"
using namespace MSXML2;
主要用来实现XML文件的相关操作,
双击"Create"按钮进入代码编写,代码如下:
void COperateXML::OnBtnCreate() 
{
// TODO: Add your control notification handler code here
::CoInitialize(NULL); //初始化COM
MSXML2::IXMLDOMDocumentPtr pDoc;
MSXML2::IXMLDOMElementPtr xmlRoot;
HRESULT hr = pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument30));
if(!SUCCEEDED(hr))
{
   MessageBox("Error");
   return;
}
pDoc->raw_createElement((_bstr_t)(char*)"china", &xmlRoot);
pDoc->raw_appendChild(xmlRoot, NULL);
MSXML2::IXMLDOMElementPtr childNode;
pDoc->raw_createElement((_bstr_t)(char*)"city", &childNode);
childNode->Puttext("shanghai");
childNode->setAttribute("population", "7000");
childNode->setAttribute("area", "2000");
xmlRoot->appendChild(childNode);
pDoc->raw_createElement((_bstr_t)(char*)"city", &childNode);
childNode->Puttext("beijing");
childNode->setAttribute("population", "39999");
childNode->setAttribute("area", "3322");
xmlRoot->appendChild(childNode);
pDoc->save("D:\\test.xml");
}
双击"GetData"按钮进入代码编写,代码如下:
void COperateXML::OnBtnGet() 
{
// TODO: Add your control notification handler code here
m_list.DeleteAllItems();
MSXML2::IXMLDOMDocumentPtr pDoc;
HRESULT hr = pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument30));
if(!SUCCEEDED(hr))
{
   MessageBox("Error!");
   return;
}
pDoc->load("D:\\test.xml");
MSXML2::IXMLDOMElementPtr childNode;
childNode = (MSXML2::IXMLDOMElementPtr)(pDoc->selectSingleNode("//city"));
MSXML2::DOMNodeType nodeType;
childNode->get_nodeType(&nodeType);
MSXML2::IXMLDOMNamedNodeMapPtr pAttrs = NULL;
MSXML2::IXMLDOMNode


相关文档:

Integration with the XML Data Type

Integration with the XML Data Type
With the introduction of the XML data type, we wanted to also give FOR XML the ability to generate an instance of XML directly (more precisely, it generates a single row, single column rowset where the cell contains the XML data type instance).
Because of the bac ......

关于struts2中的xml配置文件说明

 <package name="struts" extends="struts-default">
        <!-- class 为该action实现的类 -->
        <action name="login" class="struts2.loginaction">
          ......

把文本框的值写入到xml文件中

 protected void btn_write_Click(object sender, EventArgs e)
    {
        XmlWriterSettings settings=new XmlWriterSettings();
        settings.Indent=true;
        setting ......

dom4j 读 xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<company> 
  <tel>020-12345678-66</tel>  
  <tel>020-12345678-85</tel>  
  <introduce> 
  <![CDATA[
<br/><h1>公司简介& ......

C#生成XML文件的 函数

protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
         &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号