TXMLDocument对XML文件进行读取和写入 (bcb)
动态创建TXMLDocument对XML文件进行读取和写入 - [Delphi高级应用]
2008-01-16
Tag:Delphi XML XMLDocument
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://overblue.blogbus.com/logs/13954596.html
uses
XMLDoc, XMLIntf;
{ 写入XML内容 }
var
XMLDoc : TXMLDocument;
Node1 : IXMLNode;
Node2 : IXMLNode;
begin
XMLDoc := TXMLDocument.Create(nil);
try
XMLDoc.Active := True;
XMLDoc.Version := '1.0';
XMLDoc.Encoding := 'GB2312';
XMLDoc.Options := [doNodeAutoCreate,doNodeAutoIndent,doAttrNull,doAutoPrefix,doNamespaceDecl];
XMLDoc.DocumentElement := XMLDoc.CreateNode('ReportObjectContent');
Node1 := XMLDoc.DocumentElement;
Node1 := Node1.AddChild('ReportObjectProperty');
Node2 := Node1.AddChild('ReportName');
Node2.SetAttributeNS('Value', '', ReportName);
Node2 := Node1.AddChild('ReportType');
Node2.SetAttributeNS('Value', '', ReportType);
Node2 := Node1.AddChild('DataViewName');
Node2.SetAttributeNS('Value', '', DataViewName);
Node2 := Node1.AddChild('SQLStr');
Node2.SetAttributeNS('Value', '', SQLStr);
XMLDoc.SaveToStream(Stream);
finally
XMLDoc.Free;
end;
end;
{ 读取XML }
var
XML : TXMLDocument;
Node1 : IXMLNode;
DocIntf : IXMLDocument;
begin
XML := TXMLDocument.Create(nil);
DocIntf := XML; //防止接口被自动释放,少了这一句会发生AV
try
XML.LoadfromStream(Strem);
XML.Active := True;
{ 读ReportObject属性 }
Node1 := XML.DocumentElement.ChildNodes.FindNode('ReportObjectProperty');
Repor
相关文档:
原文:使用 MSXML 分析器处理 XML 文档
#include <atlbase.h>
#include <iostream>
using namespace std;
//<?xml version="1.0"?>
//<xmldata>
//<xmlnode />
//<xmltext>Hello, World!</xmltext>
//</xmldata>
void main ......
import java.io.StringWriter;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.apache.xerces.dom.DocumentImpl;
import org.apache.xerces.dom.DOMImplementationImpl;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.Serializer;
import org.apache.xml. ......
两种方法:
其一,使用 SelectNodes 的方法;以下例子为使用此方法的处理。
其二,使用 XQuery 的方法。
''' <summary>
''' 从 XML 文件中取得对应ID 的语言值
''' </summary>
''' <param name="textID">输入的ID< ......
JavaScript解析读取XML文件,主要就是加载并解析XML文件,然后就可以测试解析的XML文件的内容,打印输出来。
编写了一个JavaScript的类来实现读取一个XML文件中的数据,实现代码如下所示:
<mce:script type="text/javascript"><!--
/**
* @author Shirdrn
*/
function XMLDoc(){}; // 定义一个XM ......
我写的第一个程序中写XML的代码执行速度有些问题,改了一下,现在有所改善。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Data.SqlClient;
......