comp.lang.tcl
[Top] [All Lists]

Re: tdom : dealing with attributes

Subject: Re: tdom : dealing with attributes
From: "Gerald W. Lester"
Date: Fri, 30 May 2008 09:00:44 -0500
Newsgroups: comp.lang.tcl


chedderslam wrote:
I am writing a simple xml to json converter.  I have it working for a
basic xml document like this one:
<recordset>
 <division>
  <coe_division_name>mississippi valley</coe_division_name>
  <division_abbreviation>mvd</division_abbreviation>
 </division>
</recordset>

I am now trying to expand its capabilities to handle attribute values,
for documents like this:
<recordset>
 <division ATTRIBUTE="ATTRIBUTE VALUE">
  <coe_division_name>mississippi valley</coe_division_name>
  <division_abbreviation>mvd</division_abbreviation>
 </division>
</recordset>

Looking through the document at http://www.tdom.org/domNode.html, it
doesn't look like there is way way to test for the presence of
attributes.  There is the method "hasAttribute", but it takes the name
of the attribute as an argument so it doesn't do what I am looking
for.

How would I test for the presence of attribute values and then access
them?

From the page you reference (actually my local copy of it):

attributes ?attributeNamePattern?
Returns all attributes matching the attributeNamePattern. If attributeNamePattern isn't given all attributes are returned as a Tcl list.

The above will return a list of attribute names and the empty list if none is present.

To get an attribute (also on the page you reference):

getAttribute attributeName ?defaultValue?
Returns the value of the attribute attributeName. If attribute is not available defaultValue is returned.

Now a question of my own (am interested because of where I live) -- what are you doing with COE data (particularly with MVD data)?

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester                                                       |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+

<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy