Attribute value changes by Node value
Brought to you by:
mellobot
NativeXML's version 4.09.
If set value to one Node, then add to this Node an attribute and set value to this attribute - it's ok. But if after that update a value of Node then updates Attribute value, but not Node.
procedure TForm1.Button1Click(Sender: TObject); var aaa: TNativeXml; begin aaa:= TNativeXml.Create(Self); aaa.CreateName('Root'); aaa.Root.NodeNew('bbb'); aaa.Root.NodeByName('bbb').Value:='abc'; aaa.Root.NodeByName('bbb').AttributeAdd('p', '123'); aaa.Root.NodeByName('bbb').Value:='cba'; aaa.XmlFormat := xfReadable; aaa.SaveToFile('d:\123.xml'); end;
Result:
<?xml version="1.0" encoding="utf-8"?> <Root> <bbb p="cba">abc</bbb> </Root>
I don't know am i right or not, but after few hours i found a solution. This solution I was completely satisfied (for me).
I have replaced in source code 1 function and 1 procedure (TsdElement.GetValue and TsdElement.SetValue) with these:
When a Node has an attributes the variable "FValueIndex" must not be always "0", because "FNodes" has several elements like (Node1attr1, Node1attr2, ... , Node1Value, Node2attr1, Node2attr2, Node2attr3, ... , Node2Value, etc). And when "FValueIndex" is always equal "0" - FNodes[FValueIndex].Value always get a value of the first element in FNodes, which in current situation is attribute of Node, but not Node.
Hello Oam333,
Thanks for your effort and time in trying to fix NativeXml. I am not sure if I can implement your proposed changes in a timely manner but I will try. I am disabled since nov 2008 due to a horseriding acct and subsequent cerebral infarction. So I can not respond immediately but will try.
One suggestion is that I also still have an old "nativexml" version online here, called RelaxXml now. This old version has less problems, but also is less efficient and performant. However, you can test if it works for you.
Kind regards and nice to see you @ sourceforge :)
Nils Haeck M.Sc. aka mellobot
Last edit: simdesign 2015-04-24
See: http://www.simdesign.nl/mantis/view_all_bug_page.php