社区
ActiveX/COM/DCOM
帖子详情
使用TXMLDocument读取包含
qdh2002
2005-08-01 04:11:06
程序是CB6,读取别的XML内容都正常,但当读取含有<![DATA[内容的节点时,程序就发生异常:
EXMLDocError "Element does not contain a single text node"
请问如何解决???
...全文
288
3
打赏
收藏
使用TXMLDocument读取包含<![CDATA[ 内容时发生异常
程序是CB6,读取别的XML内容都正常,但当读取含有<![DATA[内容的节点时,程序就发生异常: EXMLDocError "Element does not contain a single text node" 请问如何解决???
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
hahu
2006-01-06
打赏
举报
回复
把CData当作一个子节点
if (pelem->NodeType == ntCData)
astmp = pelem->ChildNodes->Nodes[0]->NodeValue;
ccrun.com
2005-12-23
打赏
举报
回复
http://www.graphics.net.cn/bbs/delphi/0521/341.asp
小笨象
2005-12-23
打赏
举报
回复
当做子节点读取就行了。
Delphi中T
XMLDocument
控件的用法
Delphi中对XML文件的解析做的很好,比直接
使用
MS的MSXML2_TLB中的接口要方便很多,现称述于下面。 在讲之前先给出一个XML实例,在讲某些部分是要结合实例比较容易理解。
delphi_XML
unit XMLexample; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, xmldom, XMLIntf, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters, dxSkinsCore, dxSkinsDefaultPainters, StdCtrls, Buttons, cxContainer, cxListBox, msxmldom, XMLDoc; type TForm1 = class(TForm)
XMLDocument
1: T
XMLDocument
; lstSource: TcxListBox; lstTarget: TcxListBox; SpeedButton2: TSpeedButton; SpeedButton1: TSpeedButton; SpeedButton3: TSpeedButton; SpeedButton4: TSpeedButton; SpeedButton6: TSpeedButton; SpeedButton5: TSpeedButton; SpeedButton7: TSpeedButton; SpeedButton8: TSpeedButton; Button1: TButton; cxListBox1: TcxListBox; cxListBox2: TcxListBox; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure SpeedButton2Click(Sender: TObject); procedure SpeedButton1Click(Sender: TObject); procedure SpeedButton3Click(Sender: TObject); procedure SpeedButton6Click(Sender: TObject); procedure SpeedButton5Click(Sender: TObject); procedure SpeedButton7Click(Sender: TObject); private { Private declarations } public procedure MoveUp(A: TcxListBox); //上移 procedure MoveDown(A: TcxListBox); //下移 procedure DeleteItem(A: TcxListBox); //删除 procedure ReLoadItems(A: TcxListBox; const Flag: Integer = 0); //重置 procedure CreateXML(APath:string); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin CreateXML('C:\Documents and Settings\Administrator\桌面\XML'); end; procedure TForm1.Button2Click(Sender: TObject); var Node: IXMLNode; Root: IXMLNode; //根节点 ParentNode: IXMLNode; //首节点 StrDir: string;
xmlDocument
: I
XMLDocument
; I: Integer; begin
xmlDocument
:= T
XMLDocument
.Create(nil); StrDir := 'C:\Documents and Settings\Administrator\桌面\XMLConfig.xml';
xmlDocument
.XML.LoadFromFile(StrDir);
xmlDocument
.Active := true; Root :=
xmlDocument
.DocumentElement; //源字段 ParentNode:=Root.ChildNodes.FindNode('FieldsFromSource'); for I := 1 to ParentNode.ChildNodes.Count - 1 do begin Node:=ParentNode.ChildNodes[i]; cxListBox1.Items.Add(Node.ChildValues['FieldName']); end; //目标字段 ParentNode:=Root.ChildNodes.FindNode('FieldsFromTarget'); for I := 1 to ParentNode.ChildNodes.Count - 1 do begin Node:=ParentNode.ChildNodes[i]; cxListBox2.Items.Add(Node.ChildValues['FieldName']); end; end; procedure TForm1.CreateXML(APath: string); var
xmlDocument
: I
XMLDocument
; sDir: string; i:Integer; begin
xmlDocument
:= T
XMLDocument
.Create(nil); with
xmlDocument
.XML do begin //开始写XML Add(''); Add('
'); //源字段信息写入XML if lstSource.Count>0 then begin Add('
'); Add('
' + IntToStr(lstSource.Count) + '
'); for I := 0 to lstSource.Count - 1 do begin Add('
'); Add('
' + IntToStr(i) + '
'); Add('
'+ lstSource.Items[i]+'
'); Add('
'+ ''+'
'); Add('
'+ ''+'
'); Add('
'+ ''+'
'); Add('
'+ ''+'
'); Add('
'); end; Add('
'); end else begin Add('
'); Add('
0
'); Add('
'); end; //目标字段写入XML if lstTarget.Count>0 then begin Add('
'); Add('
' + IntToStr(lstTarget.Count) + '
'); for I := 0 to lstTarget.Count - 1 do begin Add('
'); Add('
' + IntToStr(i) + '
'); Add('
'+ lstTarget.Items[i]+'
'); Add('
'+ ''+'
'); Add('
'+ ''+'
'); Add('
'+ ''+'
'); Add('
'+ ''+'
'); Add('
'); end; Add('
'); end else begin Add('
'); Add('
0
'); Add('
'); end; Add('
'); //XML注释 Add(''); Add(''); Add(''); Add(''); Add(''); Add(''); Add(''); Add(''); Add(''); Add(''); //XML结束 end;
xmlDocument
.Active := True; sDir := APath; if not DirectoryExists(sDir) then begin if not CreateDir(sDir) then begin ShowMessage('创建文件夹失败'); Exit; end; end;
xmlDocument
.SaveToFile(sDir + 'Config.xml'); end; procedure TForm1.DeleteItem(A: TcxListBox); var _Index: Integer; begin with A do begin if (Items.Count > 0) and (ItemIndex <> -1) then begin _Index := ItemIndex; Items.Delete(_Index); end; end; end; procedure TForm1.MoveDown(A: TcxListBox); var CurrIndex, LastIndex: Integer; begin with A do begin CurrIndex := ItemIndex; LastIndex := Items.Count; if ItemIndex <> -1 then begin if CurrIndex + 1 < LastIndex then begin Items.Move(ItemIndex, (CurrIndex + 1)); ItemIndex := CurrIndex + 1; end; end; end; end; procedure TForm1.MoveUp(A: TcxListBox); var CurrIndex: Integer; begin with A do begin if ItemIndex > 0 then begin CurrIndex := ItemIndex; Items.Move(ItemIndex, (CurrIndex - 1)); ItemIndex := CurrIndex - 1; end; end; end; procedure TForm1.ReLoadItems(A: TcxListBox; const Flag: Integer); begin end; procedure TForm1.SpeedButton1Click(Sender: TObject); begin MoveDown(lstSource); end; procedure TForm1.SpeedButton2Click(Sender: TObject); begin MoveUp(lstSource); end; procedure TForm1.SpeedButton3Click(Sender: TObject); begin DeleteItem(lstSource); end; procedure TForm1.SpeedButton5Click(Sender: TObject); begin MoveDown(lstTarget); end; procedure TForm1.SpeedButton6Click(Sender: TObject); begin MoveUp(lstTarget); end; procedure TForm1.SpeedButton7Click(Sender: TObject); begin DeleteItem(lstTarget); end; end.
delphi中的XML解析控件T
XMLDocument
的用法.doc
delphi中的XML解析控件T
XMLDocument
的用法.doc
delphi-T
XMLDocument
.rar_T
XMLDocument
_delphi T
XMLDocument
_delphi
delphi中的XML解析控件T
XMLDocument
的用法
T
XMLDocument
例程
T
XMLDocument
例程
ActiveX/COM/DCOM
703
社区成员
3,002
社区内容
发帖
与我相关
我的任务
ActiveX/COM/DCOM
C++ Builder ActiveX/COM/DCOM
复制链接
扫一扫
分享
社区描述
C++ Builder ActiveX/COM/DCOM
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章