这是我的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<UsersF Ver="1.1">
<row User="1" Pin="2y44ic" ExtPag="full"/>
<row User="2" pin="tfde88" ExtPag="e45" />
<row User="3" Pin="9gr444466gg" Level="nov" GamePag="3" />
</UsersF>
这是我获得访问权限并放置字符串网格的代码......我使用下一个网格...
procedure showXmlToString;
Count:= 0;
Conf.nxtgrd.AddRow(71);
Conf.nxtgrd.BeginUpdate;
with FXml.Root do
for i := 0 to NodeCount - 1 do
begin
if Nodes[i].Name <> 'Ver' then
begin
Conf.nxtgrd.Cell[0,count].AsString := Nodes[i].Nodes[1].Value;
Conf.nxtgrd.Cell[1,count].AsString := Nodes[i].Nodes[2].Value;
Conf.nxtgrd.Cell[2,count].AsString := Nodes[i].Nodes[3].Value;
Conf.nxtgrd.Cell[3,count].AsString := Nodes[i].Nodes[4].Value;
count := count + 1;
end;
end;
当涉及到节点未退出的行时,我收到错误。
要访问属性,您可以使用TXmlNode.AttributeCount
来迭代可用属性的数量。如果此代码的要点是获取属性,则可以使用 TXmlNode.Containers
访问它们。
假设你想获取所有属性名称和值,你可以使用以下迭代:
with FXML.Root do
for i := 0 to ContainerCount - 1 do
begin
Log(Format('ContainersName=%s AtribNumber=%d',[Containers[i].Name,i]));
for j:=0 to Containers[i].AttributeCount-1 do begin
Log(Format('AttribName=%s AttribVal=%s',[Containers[i].Attributes[j].Name,Containers[i].Attributes[j].Value]));
end;
end;
在此示例中Log
过程将在屏幕上显示字符串。结果,输出将如下所示:
ContainersName=row AtribNumber=0
AttribName=User AttribVal=1
AttribName=Pin AttribVal=2y44ic
AttribName=ExtPag AttribVal=full
ContainersName=row AtribNumber=1
AttribName=User AttribVal=2
AttribName=pin AttribVal=tfde88
AttribName=ExtPag AttribVal=e45
ContainersName=row AtribNumber=2
AttribName=User AttribVal=3
AttribName=Pin AttribVal=9gr444466gg
AttribName=Level AttribVal=nov
AttribName=GamePag AttribVal=3
我希望这对你有所帮助。