试题:
1. 写一个函数F,读入以下一段xml(样例)到RichEdit,要求如下:
1)显示格式 ,其中"大","合格"==>变成蓝色下划线.Option中的子节点显示第一个节点.
工程大,测试合格 2)读入后,要保存为新xml,填充属性值caretpos和itemlen.
Caretpos为每个蓝色下划线部份开始所在richedit中光标位置.
ItemLen为蓝色下划线部份的文字长度. 2.任意编辑RichEdit中内容,能实时更新这份xml.可以称之为"双向翻译',
编辑后RichEdit中的内容及格式称为X,X能用xml表示,这段xml称为A
反之,用第1个题目写的函数F加载A,必须能显示出X其中,第1个题目倒不是难.
第2个题目,我想到头大....真的很难哦...
<?xml version="1.0" encoding="gb2312" standalone="no"?>
<template xmlns="">
<text xmlns="">工程</text>
<option xmlns="" caretpos="5" itemlen="2">
<item xmlns="">大</item>
<item xmlns="">中</item>
<item xmlns="">小</item>
</option>
<text xmlns="">,测试</text>
<option xmlns="" caretpos="13" itemlen="6">
<item xmlns="">合格</item>
<item xmlns="">不合格</item>
<item xmlns="">劣</item>
</option>
.....
....
</template>
1. 写一个函数F,读入以下一段xml(样例)到RichEdit,要求如下:
1)显示格式 ,其中"大","合格"==>变成蓝色下划线.Option中的子节点显示第一个节点.
工程大,测试合格 2)读入后,要保存为新xml,填充属性值caretpos和itemlen.
Caretpos为每个蓝色下划线部份开始所在richedit中光标位置.
ItemLen为蓝色下划线部份的文字长度. 2.任意编辑RichEdit中内容,能实时更新这份xml.可以称之为"双向翻译',
编辑后RichEdit中的内容及格式称为X,X能用xml表示,这段xml称为A
反之,用第1个题目写的函数F加载A,必须能显示出X其中,第1个题目倒不是难.
第2个题目,我想到头大....真的很难哦...
<?xml version="1.0" encoding="gb2312" standalone="no"?>
<template xmlns="">
<text xmlns="">工程</text>
<option xmlns="" caretpos="5" itemlen="2">
<item xmlns="">大</item>
<item xmlns="">中</item>
<item xmlns="">小</item>
</option>
<text xmlns="">,测试</text>
<option xmlns="" caretpos="13" itemlen="6">
<item xmlns="">合格</item>
<item xmlns="">不合格</item>
<item xmlns="">劣</item>
</option>
.....
....
</template>
就是要接管richedit中的keydown和mousedown事件,
如 : 删除字符,如果删除蓝色一部份,则更新xml时就要删除其option所有节点,将剩下的部份文字并入前面的text.
工程大,测试合格
(大,合格 ==>蓝色下划线)如果选择删除"试合",则变成
工程大,测格
("格"字,没有蓝色下划线. 对应于xml,它跟之前的text合并)
http://blogger.cn/hkbarton/posts/18129.aspx
procedure ShowXML(var sXML :String ;RichEdit :TRichEdit);
var
i :integer;
sTemp ,sBody :String;
RootNode,ParentNode :IXMLNode;
begin sTemp := '';
sBody := '';
for i := 0 to RootNode.ChildNodes.Count - 1 do
begin
ParentNode := RootNode.ChildNodes.Nodes[i];
if (not ParentNode.HasChildNodes) then continue;
sTemp := String(ParentNode.ChildNodes.Nodes[0].Text);
if (ParentNode.NodeName = String('option')) then
begin
ParentNode.SetAttribute('caretpos', Length(sBody));
ParentNode.SetAttribute('itemlen', Length(sTemp));
end;
sBody := sBody + sTemp;
end; // 显示xml
with RichEdit do
begin
Lines.BeginUpdate;
try
Lines.Clear;
Lines.Text := sBody;
for i :=0 to RootNode.ChildNodes.Count - 1 do
begin
ParentNode := RootNode.ChildNodes.Nodes[i];
if (ParentNode.NodeName = String('option')) then
begin
SelStart := pParentNode.GetAttribute('caretpos');
SelLength := pParentNode.GetAttribute('itemlen');
SelAttributes.Color := clBlue;
SelAttributes.Style := [fsUnderline];
end;
end; SetFocus;
SelStart := 0;
SelLength := 0;
finally
Lines.EndUpdate;
end;
end; // with
end;
procedure ShowXML(var sXML :String ;RichEdit :TRichEdit);
var
i :integer;
sTemp ,sBody :String;
RootNode,ParentNode :IXMLNode;
begin
XMLDocument.LoadFromXML(sTemplate);
RootNode := XMLDocument.DocumentElement;
sTemp := '';
sBody := '';
for i := 0 to RootNode.ChildNodes.Count - 1 do
begin
ParentNode := RootNode.ChildNodes.Nodes[i];
if (not ParentNode.HasChildNodes) then continue;
sTemp := String(ParentNode.ChildNodes.Nodes[0].Text);
if (ParentNode.NodeName = String('option')) then
begin
ParentNode.SetAttribute('caretpos', Length(sBody));
ParentNode.SetAttribute('itemlen', Length(sTemp));
end;
sBody := sBody + sTemp;
end; // 显示xml
with RichEdit do
begin
Lines.BeginUpdate;
try
Lines.Clear;
Lines.Text := sBody;
for i :=0 to RootNode.ChildNodes.Count - 1 do
begin
ParentNode := RootNode.ChildNodes.Nodes[i];
if (ParentNode.NodeName = String('option')) then
begin
SelStart := pParentNode.GetAttribute('caretpos');
SelLength := pParentNode.GetAttribute('itemlen');
SelAttributes.Color := clBlue;
SelAttributes.Style := [fsUnderline];
end;
end; SetFocus;
SelStart := 0;
SelLength := 0;
finally
Lines.EndUpdate;
end;
end; // with
end;
而是考你对XML DOM 以及XSL转换技术的熟悉程度。。
当然,也包括RTF格式处理。RTF==》XML
XML==》RTF
这两种XSL转换在网上可以找到很多文章可以参考,但具体实现还得靠你自己。
这个题目是检测:
1。将option部份标记为蓝色下划线
2。将蓝色下划线部分进行“tag".这个"tag"对应于如何填充xml中的两个属性。
3。考察一些delphi技术和熟练程度。
XML没有仔细学
我回学校赶紧补吧,太落后了~~