支持xml的控件(200分)

  • 主题发起人 主题发起人 query
  • 开始时间 开始时间
管用的load的参数也可以是location url
 
如果你的组件有源代码,一切好办,改一改源代码就行了,
把package文件里边的require语句一改就行了。
如果没有,就拷贝一个delphi 4.0的文件,安装上再说!
 
lczhuohuo您好:
我试过了你的小程序,确实是我要分析的xml文件不是良好格式,导致以前不能成功运行。
在此,也谢谢flyflyfly和woodstock二位。希望能一直帮助我,谢谢!
 
对了,lczhuohuo请您帮我看一下下面的xml是不是良好格式的文件(标签关闭、没有交叉、
属性都有引号,按理说应该属于well-format的及格文件吗?)源码如下:
<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet type="text/xsl" href="/NewsML/rosstyle.xsl"?>
<!DOCTYPE newsitem SYSTEM "/NewsML/newsml.dtd">
<newsitem date="2000-08-03T01:48:51+0000" itemid="nCH0059733" parts="1" revision="0">
<title>[香港个股]集团&amp;lt;1013.HK&amp;gt;暂停股份买卖</title>
<headline>[香港个股]骏泰集团&amp;lt;1013.HK&amp;gt;暂停股份买卖</headline>
<text>
<p> [香港3日电] 香港联交所周四表示,从事生产消费电子产品及玩具的集团有限公司要求暂停其股份买卖,等候发表内容涉及配售新股的通告. </p>
<p> 该股周三收报0.41港元. (完) </p>
<p> </p>
</text>
<copyright> (c) 2000 Reuters Limited. All rights reserved. Republication or redistribution of Reuters content, including by framing or similar means, is expressly prohibited without the prior written consent of Reuters.</copyright>
<metadata>
<codes class="topic">
<code code="ASIA" present="true" />
<code code="HK" present="true" />
<code code="LZH" present="true" />
<code code="RTRS" present="true" />
<code code="HOT" present="true" />
<code code="ANP" present="true" />
<code code="ISU" present="true" />
<code code="ELI" present="true" />
</codes>
<codes class="product">
<code code="CMN" present="true" />
<code code="CSN" present="true" />
<code code="CDS" present="true" />
<code code="CLN" present="true" />
</codes>
<codes class="co_ids">
<code code="1013" present="true" />
</codes>
</metadata>
<handling>
<routing>IDN_SELECTFEED</routing>
<status>story</status>
</handling>
</newsitem>
如果是,为什么不能load及save呢?盼回信,可以发mail给我,我随时能监控到。谢谢!
 
很奇怪源码怎么不见了?
 
以前帮别人写的一个例子,你可以参考一下 :)
unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
OleServer, MSXML2_TLB, StdCtrls, AppEvnts, ComCtrls, XMLTreeView;
type
EXMLError = class(Exception);
EXMLLoadError = class(EXMLError);
EXMLSaveError = class(EXMLError);
EXMLParseError = class(EXMLError);
type
TfrmMain = class(TForm)
memXML: TMemo;
btnLoad: TButton;
dlgOpen: TOpenDialog;
AppEvents: TApplicationEvents;
lblTagName: TLabel;
edtTagName: TEdit;
lstChildren: TListBox;
btnTree: TButton;
treeNode: TTreeView;
dlgSave: TSaveDialog;
btnSave: TButton;
XMLTree: TXMLTreeView;
btnLoadFromFile: TButton;
btnSaveToFile: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btnLoadClick(Sender: TObject);
procedure AppEventsException(Sender: TObject;
E: Exception);
procedure edtTagNameChange(Sender: TObject);
procedure btnTreeClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
procedure btnLoadFromFileClick(Sender: TObject);
procedure btnSaveToFileClick(Sender: TObject);
private
xmlDoc: IXMLDOMDocument2;
public
{ Public declarations }
end;

var
frmMain: TfrmMain;
implementation
{$R *.DFM}
procedure TfrmMain.FormCreate(Sender: TObject);
begin
xmlDoc := CoDOMDocument.Create;
end;

procedure TfrmMain.FormDestroy(Sender: TObject);
begin
xmlDoc := nil;
end;

procedure TfrmMain.btnLoadClick(Sender: TObject);
begin
with dlgOpen, xmlDocdo
if Execute then
begin
if not Load(FileName) then
raise EXMLLoadError.CreateFmt('载入XML文档失败!', [FileName])
else
with memXML.Linesdo
begin
Clear;
Text :=do
cumentElement.xml;
end;
end;
end;

procedure TfrmMain.btnSaveClick(Sender: TObject);
begin
with dlgSavedo
if Execute then
xmlDoc.Save(FileName);
end;

procedure TfrmMain.AppEventsException(Sender: TObject;
E: Exception);
begin
if E is EXMLError then
with xmlDoc.parseErrordo
begin
MessageDlg(Format('处理文档"%s"时因"%s"发生0x%x号错误在第%d行%d个字符(全文第%d个字符)'#13#10'错误文本: %s'#13#10'提示信息: %s',
[url, reason, errorCode, line, linepos, filepos + 1, srcText, E.Message]), mtError, [mbAbort], 0);
end
else
Application.ShowException(E);
end;

procedure TfrmMain.edtTagNameChange(Sender: TObject);
var
I: Integer;
begin
if edtTagName.Text <> '' then
with xmlDoc.getElementsByTagName(UpperCase(edtTagName.Text))do
with lstChildren.Itemsdo
begin
Clear;
for I := 0 to length - 1do
Add(item.text);
end;
end;

procedure TfrmMain.btnTreeClick(Sender: TObject);
proceduredo
Tree(ANode: IXMLDOMNode;
Parent: TTreeNode);
var
I: Integer;
CurNode: TTreeNode;
begin
with ANodedo
case nodeType of
NODE_ELEMENT:
begin
if ParentNode = nil then
CurNode := treeNode.Items.Add(nil, nodeName)
else
CurNode := treeNode.Items.AddChild(Parent, nodeName);
if hasChildNodes then
with childNodesdo
for I := 0 to length - 1do
do
Tree(IXMLDOMElement(item), CurNode);
end;
NODE_TEXT:
treeNode.Items.AddChild(Parent, ANode.text);
end;
end;
begin
with treeNode.Itemsdo
begin
Clear;
begin
Update;
do
Tree(xmlDoc.documentElement, nil);
treeNode.FullExpand;
EndUpdate;
end;
end;

procedure TfrmMain.btnLoadFromFileClick(Sender: TObject);
begin
with dlgOpendo
if Execute then
XMLTree.LoadFromFile(FileName);
end;

procedure TfrmMain.btnSaveToFileClick(Sender: TObject);
begin
with dlgSavedo
if Execute then
XMLTree.SaveToFile(FileName);
end;

end.
 
不知道上边这位老兄的TXMLTreeView是从哪里来的。
query,你看不到源代码的原因是因为ie5对它进行解析了,
没问题,我可以这样:查看->源文件,看了一下,
发现是dtd的毛病了,其实你可以这样,处理不了的,
拿到ie中浏览一下,ie会给出错误信息的,你就能知道是
怎么回事了。
你给出的那个xml的dtd一定要在正确的目录中。
 
那个TXMLTreeView其实就是把TTreeView改了一下,把它那个土土的SaveToStream
LoadFromStream改成了使用XML格式,而不是通过/t来定位而已,很简单的说
 
多人接受答案了。
 
后退
顶部