TXMLDocument
TXMLDocument is a component used for programming XML documents. It takes car
e of getting an instance of a IDOMDocument interface and loading and saving
xml files. After setting the filename property and setting Active to true, u
se the DOMDocument property to access the contents of the file.
TXMLDocument is a component used for programming XML documents. It takes car
e of getting an instance of a IDOMDocument interface and loading and saving
xml files. After setting the filename property and setting Active to true, u
se the DOMDocument property to access the contents of the file.
解决方案 »
- 求教一个也是是数据结构也许是算法的问题
- 求教关于生成ID的
- 解析XML引起CPU占用率达100%的问题
- vcl for the web与intraweb是什么关系,刚装了delphi2007架构师版,找不到intraweb了
- 為什麼在win2000下開發的ADO聯sql2000在win98下出現不同情況的問題?
- 求解加密算法?!能否直接对Variant型数据进行加密
- sql 语句 错在哪儿??? 我调试了很久
- 高分求解!sun solaris8.0+oracle 8.1.7,客户端连接有时正常,有时不正常。配置文件如下
- 在下收集老版本Delphi~~~
- 为何DBgrid只可显示小数点后的四位,不知如何显示更多位?
- 我要在程序里结束dllhost.exe进程,怎么写啊?
- 内嵌窗口的问题
如果你一定是要用TXMLDocument,那我UP。
[email protected]
而msxml4.0很好用!
这是一套com组件,比较简单把,而且刚出了正式版,还有中文4.0正式版,赶快下载了!:)
当文本文件生成好了,然后用TXmldocument.loadfromfile将它load进来。
Private Sub CmdOpenXml_Click()
Dim LsHour As String
Dim LsMin As String
Dim LsSec As String
Dim TimeB As String
Dim TimeE As String
Dim msTime As String
Dim lTime As SystemTime
Dim bM, eM As Integer
Dim bMs, eMs As Integer
Dim bMm, eMm, costTime As Integer
Dim Rslt As Variant
Dim Node As IXMLDOMNode 'ノードを取得
Dim Rootdoc As DOMDocument 'ルートノードをゲット
On Err GoTo Eh
GetLocalTime lTime
'データ読み込む開始時刻を取得
bM = lTime.wMinute
bMs = lTime.wMilliseconds
bMm = lTime.wSecond
LsHour = CStr(lTime.wHour)
LsMin = CStr(lTime.wMinute)
LsSec = CStr(lTime.wSecond)
msTime = CStr(lTime.wMilliseconds)
TimeB = LsHour & ":" & LsMin & ":" & LsSec & " : " & msTime
LblXmlB.Caption = "開始時刻:" + TimeB 'XMLファイルのデータを読み込む、フィールドまで分ける
LstTree.Clear
Set Rootdoc = New DOMDocument
Rootdoc.async = False '非同期処理を行わない
Rootdoc.validateOnParse = False '文書型定義を検証しない
Rootdoc.preserveWhiteSpace = False 'WhiteSpaceを含めない
If (Rootdoc.Load(XMLFILE)) Then
Set Node = Rootdoc.childNodes(1)
Rslt = getNodeData(Node)
End If
GetLocalTime lTime
'データ読み込む終了時刻を取得
eM = lTime.wMinute
eMs = lTime.wMilliseconds
eMm = lTime.wSecond
LsHour = CStr(lTime.wHour)
LsMin = CStr(lTime.wMinute)
LsSec = CStr(lTime.wSecond)
msTime = CStr(lTime.wMilliseconds)
TimeE = LsHour & ":" & LsMin & ":" & LsSec & " : " & msTime
LblXmlE.Caption = "終了時刻:" + TimeE
costTime = ((eM - bM) * 60 + eMm - bMm) * 1000 + eMs - bMs
Label1.Caption = CStr(costTime) + "ミリ秒"
Exit Sub
Eh:
'XMLファイルオープン失敗
MsgBox Err.Description
End SubPrivate Function getNodeData(ByVal nodeData As IXMLDOMNode) As Variant
Dim rt As Variant
Dim i, j, num, chnt As Integer
Dim atrrName, atrrValue, RecordData As String
Dim NodeMap As IXMLDOMNamedNodeMap 'ノードの属性を取得
RecordData = nodeData.nodeName
'当ノートの属性を判断、つまり、要素の属性が有否を判断する
Set NodeMap = nodeData.Attributes
num = NodeMap.Length
If num > 0 Then
For i = 0 To num - 1
atrrName = NodeMap.Item(i).nodeName '要素の属性の名前
atrrValue = NodeMap.Item(i).nodeValue '要素の属性の値
RecordData = RecordData + atrrName & ":" & atrrValue
Next i
LstTree.AddItem (RecordData)
'当ノートは子ノートがあれば、コールセルフ
If (nodeData.hasChildNodes) Then
chnt = nodeData.childNodes.Length
For j = 0 To chnt - 1
rt = getNodeData(nodeData.childNodes(j))
Next j
Else
'当ノートは子ノートが無し、これはDOMツリーの最後の階層
Exit Function
End If
End If
End Function