Re: TXMLDocument and TTreeView



On Jul 27, 3:00 pm, Cafetorium <p...@xxxxxxxxxxxxxxxx> wrote:
On Jul 26, 5:01 pm, "Chris.Cheney" <Chris.CheneyXXNOSPA...@xxxxxxxxx>
wrote:



Cafetorium <p...@xxxxxxxxxxxxxxxx> wrote innews:1185463770.014386.97620@xxxxxxxxxxxxxxxxxxxxxxxxxxxx:

On Jul 26, 4:22 pm, Cafetorium <p...@xxxxxxxxxxxxxxxx> wrote:
On Jul 26, 3:54 pm, "Chris.Cheney" <Chris.CheneyXXNOSPA...@xxxxxxxxx>
wrote:

Cafetorium <p...@xxxxxxxxxxxxxxxx> wrote in
news:1185459002.704130.267600 @l70g2000hse.googlegroups.com:

I've been tinkering with the idea of using a TTreeView to display
the contents of an XML file.

I can parse the TXMLDocument and add nodes to the tree with no
problems, but it would be really useful if I could attach each
node to the Data property so that I can access it immediately.

The Data porperty is a (System.)Pointer, but the object I use
when traversing the XML Document is a (XMLIntf.)IXMLNode, and I
can't work out how to use these two together.

I tried
tn.Data := addr(iNode);
which worked ok.

Then in my TreeView OnClick method, I want to get the XML node
back again by accessing the Data object, but I can't work out how
to do it.

iNode := tn.Data^;
doesn't work, and neither does
iNode := tn.Data^ as IXMLNode;

I guess this is something to do with the fact that IXMLNode is an
interface and I don't really understand how it works.

Can anyone enlighten me, please?

Phil

IXMLNode(tn.Data) := iNode;

iNode := IXMLNode(tn.Data); // or
iNode := IInterface(tn.Data) as IXMLNode; // if the QI is needed

And, when the treenode is destroyed, don't forget to

IXMLNode(tn.Data) := nil;

Casting the treenode in the above cases will cause the compiler to
generate the appropriate interface reference-counting code which
will not happen if you take the other alternative of casting the
interface to a pointer.

You may be better off using a custom tree node type (provision for
which was added in Delphi 6) with an explicit IXMLNode property.

Thanks for the rapid reply.
In the meantime, I've found an alternative XMLDocument component on
Torry.
The XML nodes it creates are objects, so Data can point to them just
like any other object.

However, I'll give your suggestion a try because I want to stick with
the standard component.

Phil

Hmmm. Tried it and got:

IXMLNode(tn.Data) := iNode;

E2064 Left side cannot be assigned to
E2010 Incompatible types: 'IXMLNode' and 'Pointer'

Sorry, I should have checked that the Data property of a TTreeNode was
not a method.

Use Plan B above.

Still no luck with this. I think I'll be using the alternative XML
Document component that I mentioned before unless anyone else can
suggest anything.

Hey, I've just discovered the XML Mapper which lets you create
transformations between XML and Datasets and vice versa.
About a year ago, using VB .NET, I discovered that you could open an
XML file in a Dataset, and it was incredibly useful.
It looks as if XML Mapper will help me do something similar.

Then I can simply have the XML file open and navigate it like a
database. Instead of attaching data to my TreeView, I should be able
to use the TreeView OnClick event to determine which node to navigate
to in the XML file.


.



Relevant Pages

  • Re: xml in plain text file on heavy load.
    ... even if the XML file is magically and perfectly ... I want to emphasize that IIS would never be caching that XML file on its own ... Application is NOT synchronizing access to your ASP pages. ...
    (microsoft.public.inetserver.iis)
  • Re: TAPI 3.0 call attached data
    ... The format of the Call Attached Data is XML. ... XML file with CallAttchedData represents one or multiple data lists ... Root element is CallAttachedData. ... version CDATA #FIXED "1.0" ...
    (microsoft.public.win32.programmer.tapi)
  • Re: XML parser and writer
    ... them on a calendar. ... Therefore I will need to both easily parse and write new XML files. ... why not some database technology? ... an advanced user can edit the XML file directly at ...
    (comp.lang.java.programmer)
  • Re: Zooming Out: The Larger Issue
    ... XML file or a binary file (smaller and faster to serialize deserialize, ... On startup of your app you could just check if the xml / binary file exists ... datarow = the container of one or more datacolumns wich in there turn hold ...
    (microsoft.public.dotnet.languages.vb)
  • Re: XmlTextReader or XmlDocument or SQLCE
    ... I wouldn't really call it "unrealistic expectations", ... I would love to see a 1 second response time ... reading a single node from a 200k XML file on any version of CF running on ... > As to saving XML file after each change, ...
    (microsoft.public.dotnet.framework.compactframework)