Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-12

How to read TDOMNode attributes

10 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mattias Gaertner
to Frank Church
Is there a way of knowning the attribute count of a TDOMNode as well as reading the value of an attribute if it exists?
HasAttribute:=(Node is TDOMElement) and
(TDOMElement.hasAttribute('Name'));

Attribute value:

if Node is TDOMElement then
  Value:=TDOMElement(Node).GetAttribute('Name')
else
  Value:='';

Mattias

Reply by email

Frank Church
to Mattias Gaertner
Mattias Gaertner wrote 22 lines
On Fri, 2 Dec 2011 18:59:25 +0000 Frank Church wrote: > Is there a way of knowning the attribute count of a TDOMNode as well as > reading the value of an attribute if it exists? HasAttribute:=(Node is TDOMElement) and (TDOMElement.hasAttribute('Name')); Attribute value: if Node is TDOMElement then Value:=TDOMElement(Node).GetAttribute('Name') else Value:=''; Mattias _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Is there a way of counting the attributes and listing them out if you don't know what they are in advance, or some kind of iteration which will tell you when you are on the last item or there are none at all?

Frank Church ======================= http://devblog.brahmancreations.com

Reply by email

Mattias Gaertner
to Frank Church
Show quoted text 28 lines
On 2 December 2011 19:09, Mattias Gaertner wrote: > On Fri, 2 Dec 2011 18:59:25 +0000 > Frank Church wrote: > > > Is there a way of knowning the attribute count of a TDOMNode as well as > > reading the value of an attribute if it exists? > > HasAttribute:=(Node is TDOMElement) and > (TDOMElement.hasAttribute('Name')); > > Attribute value: > > if Node is TDOMElement then > Value:=TDOMElement(Node).GetAttribute('Name') > else > Value:=''; > > > Mattias > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > Is there a way of counting the attributes and listing them out if you don't know what they are in advance, or some kind of iteration which will tell you when you are on the last item or there are none at all?

You may want to read the fpc xml tutorial:
http://wiki.freepascal.org/XML_Tutorial#Printing_the_names_of_nodes_and_attributes

Mattias

Reply by email

Frank Church
to Mattias Gaertner
Mattias Gaertner wrote 44 lines
On Fri, 2 Dec 2011 19:30:17 +0000 Frank Church wrote: > On 2 December 2011 19:09, Mattias Gaertner < >wrote: > > > On Fri, 2 Dec 2011 18:59:25 +0000 > > Frank Church wrote: > > > > > Is there a way of knowning the attribute count of a TDOMNode as well as > > > reading the value of an attribute if it exists? > > > > HasAttribute:=(Node is TDOMElement) and > > (TDOMElement.hasAttribute('Name')); > > > > Attribute value: > > > > if Node is TDOMElement then > > Value:=TDOMElement(Node).GetAttribute('Name') > > else > > Value:=''; > > > > > > Mattias > > _______________________________________________ > > fpc-pascal maillist - > > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > > > > Is there a way of counting the attributes and listing them out if you don't > know what they are in advance, or some kind of iteration which will tell > you when you are on the last item or there are none at all? You may want to read the fpc xml tutorial: http://wiki.freepascal.org/XML_Tutorial#Printing_the_names_of_nodes_and_attributes Mattias _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

The example you pointed doesn't show what I am looking for, but it led me to one that does -
http://wiki.freepascal.org/XML_Tutorial#Populating_a_TreeView_with_XML.

The method in question is the TDomNode.Attributes.Length property. I thought something like that shoud exist but I was looking for a Count property. Shouldn't it be count instead?

Frank Church ======================= http://devblog.brahmancreations.com

Reply by email

Sven Barth
to Frank Church
Frank Church wrote 61 lines
On 2 December 2011 19:45, Mattias Gaertner < > wrote: On Fri, 2 Dec 2011 19:30:17 +0000 Frank Church < > wrote: > On 2 December 2011 19:09, Mattias Gaertner < >wrote: > > > On Fri, 2 Dec 2011 18:59:25 +0000 > > Frank Church < > wrote: > > > > > Is there a way of knowning the attribute count of a TDOMNode as well as > > > reading the value of an attribute if it exists? > > > > HasAttribute:=(Node is TDOMElement) and > > (TDOMElement.hasAttribute('Name')); > > > > Attribute value: > > > > if Node is TDOMElement then > > Value:=TDOMElement(Node).GetAttribute('Name') > > else > > Value:=''; > > > > > > Mattias > > _______________________________________________ > > fpc-pascal maillist - > > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > > > > Is there a way of counting the attributes and listing them out if you don't > know what they are in advance, or some kind of iteration which will tell > you when you are on the last item or there are none at all? You may want to read the fpc xml tutorial: http://wiki.freepascal.org/XML_Tutorial#Printing_the_names_of_nodes_and_attributes Mattias _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal The example you pointed doesn't show what I am looking for, but it led me to one that does - http://wiki.freepascal.org/XML_Tutorial#Populating_a_TreeView_with_XML. The method in question is the TDomNode.Attributes.Length property. I thought something like that shoud exist but I was looking for a Count property. Shouldn't it be count instead?

FPC's XML implementation is based on the DOM specification by W3C. And there it defined as "length". Also changing it to "count" would break existing code.

Regards,
Sven

Reply by email

Frank Church
to Sven Barth
Sven Barth wrote 81 lines
On 02.12.2011 21:26, Frank Church wrote: > > > On 2 December 2011 19:45, Mattias Gaertner < > > < >> wrote: > > On Fri, 2 Dec 2011 19:30:17 +0000 > Frank Church < > wrote: > > > On 2 December 2011 19:09, Mattias Gaertner > < < > >>wrote: > > > > > > On Fri, 2 Dec 2011 18:59:25 +0000 > > > Frank Church < > > > wrote: > > > > > > > Is there a way of knowning the attribute count of a TDOMNode > as well as > > > > reading the value of an attribute if it exists? > > > > > > HasAttribute:=(Node is TDOMElement) and > > > (TDOMElement.hasAttribute('**Name')); > > > > > > Attribute value: > > > > > > if Node is TDOMElement then > > > Value:=TDOMElement(Node).**GetAttribute('Name') > > > else > > > Value:=''; > > > > > > > > > Mattias > > > ______________________________**_________________ > > > fpc-pascal maillist - > < > > > > > > http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal> > > > > > > > Is there a way of counting the attributes and listing them out if > you don't > > know what they are in advance, or some kind of iteration which > will tell > > you when you are on the last item or there are none at all? > > You may want to read the fpc xml tutorial: > http://wiki.freepascal.org/**XML_Tutorial#Printing_the_** > names_of_nodes_and_attributes<http://wiki.freepascal.org/XML_Tutorial#Printing_the_names_of_nodes_and_attributes> > > Mattias > ______________________________**_________________ > fpc-pascal maillist - > < > > > > http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal> > > > > The example you pointed doesn't show what I am looking for, but it led > me to one that does - > http://wiki.freepascal.org/**XML_Tutorial#Populating_a_** > TreeView_with_XML<http://wiki.freepascal.org/XML_Tutorial#Populating_a_TreeView_with_XML> > . > > The method in question is the TDomNode.Attributes.Length property. I > thought something like that shoud exist but I was looking for a Count > property. Shouldn't it be count instead? > FPC's XML implementation is based on the DOM specification by W3C. And there it defined as "length". Also changing it to "count" would break existing code.

I am now familiarizing myself with XML. I suspect anyway that there had to be a reason for it.

Show quoted text 7 lines
Regards, Sven ______________________________**_________________ fpc-pascal maillist - http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>
Frank Church ======================= http://devblog.brahmancreations.com

Reply by email

Graeme Geldenhuys
to Frank Church: The example you pointed doesn't show what I am looking for, but it led me to one that…
Frank Church wrote
The method in question is the TDomNode.Attributes.Length property. I thought something like that shoud exist but I was looking for a Count property. Shouldn't it be count instead?

Talk about not being very intuitive. As I mentioned in another thread, the DOM unit is pretty damn programmer unfriendly. I don't care if it is W3C compliant or not, it just isn't logical or intuitive at all.

I'm with you on this one Frank. I would have though the number of attributes, or child nodes etc would use a Count property. If it ever comes down to it, and I am forced to use XML in a project, I would write a much more simplified API to the DOM unit. GetNode(ANodePath), ChildCount, Attribute[] and AttributeCount would be on the top of my list.

Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net

Reply by email

Frank Church
to Graeme Geldenhuys
Graeme Geldenhuys wrote 21 lines
On 2 December 2011 22:26, Frank Church wrote: > > The method in question is the TDomNode.Attributes.Length property. I thought > something like that shoud exist but I was looking for a Count property. > Shouldn't it be count instead? Talk about not being very intuitive. As I mentioned in another thread, the DOM unit is pretty damn programmer unfriendly. I don't care if it is W3C compliant or not, it just isn't logical or intuitive at all. I'm with you on this one Frank. I would have though the number of attributes, or child nodes etc would use a Count property. If it ever comes down to it, and I am forced to use XML in a project, I would write a much more simplified API to the DOM unit. GetNode(ANodePath), ChildCount, Attribute[] and AttributeCount would be on the top of my list.

My own thought was that it would be good to have a Count property that is aliased to Length (and documented as such). The downside of using Object Pascal norms is that someone new to Object Pascal but well versed in the DOM would be looking for would be looking for direct mappings of the properties.

Show quoted text 12 lines
-- Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Frank Church ======================= http://devblog.brahmancreations.com

Reply by email

Marco van de Voort
to Graeme Geldenhuys: Talk about not being very intuitive. As I mentioned in another thread, the DOM unit is…

In our previous episode, Graeme Geldenhuys said:

Show quoted text 8 lines
> The method in question is the TDomNode.Attributes.Length property. I thought > something like that shoud exist but I was looking for a Count property. > Shouldn't it be count instead? Talk about not being very intuitive. As I mentioned in another thread, the DOM unit is pretty damn programmer unfriendly. I don't care if it is W3C compliant or not, it just isn't logical or intuitive at all.

Use a simple wrapper unit over it. I use the xml config stuff of lazarus for most purposes, with some minor own additions. Syncing and minimizing this, is still on my todo. (I took this copy before Sergei started to massively work on this, from the fpdoc work I know it is now massively better)

comes down to it, and I am forced to use XML in a project, I would write a much more simplified API to the DOM unit. GetNode(ANodePath), ChildCount, Attribute[] and AttributeCount would be on the top of my list.

Sounds like a fine idea.

Reply by email