Is there a way of knowning the attribute count of a TDOMNode as well as reading the value of an attribute if it exists?
Mailing lists / fpc-pascal / 2011-12
How to read TDOMNode attributes
10 messages · 5 people · –
- FFrank Church 5
- MMattias Gaertner 2
- GGraeme Geldenhuys 1
- MMarco van de Voort 1
- SSven Barth 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
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
Mattias Gaertner wrote 22 lines
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?
Show quoted text 28 lines
You may want to read the fpc xml tutorial:
http://wiki.freepascal.org/XML_Tutorial#Printing_the_names_of_nodes_and_attributes
Mattias
Mattias Gaertner wrote 44 lines
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 wrote 61 lines
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
Sven Barth wrote 81 lines
I am now familiarizing myself with XML. I suspect anyway that there had to be a reason for it.
Show quoted text 7 lines
The example you pointed doesn't show what I am looking for, but it led me to one that…
Frank Church wroteThe 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.
Graeme Geldenhuys wrote 21 lines
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
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
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.
