Index: doc/domNode.html ================================================================== --- doc/domNode.html +++ doc/domNode.html @@ -2,22 +2,22 @@ tDOM manual: domNode
-

NAME

+

NAME

domNode -
Manipulates an instance of a DOM node object

-

SYNOPSIS

$nodeObject method arg arg ...
+  

SYNOPSIS

$nodeObject method arg arg ...
 
domNode nodeToken method arg arg ...
 
-

DESCRIPTION

This command manipulates one particular instance of a DOM node object. +

DESCRIPTION

This command manipulates one particular instance of a DOM node object. method indicates a specific method of the node class. These methods should closely conform to the W3C recommendation "Document Object Model (Core) Level 1" (http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html) as well to parts of the W3C draft "XML Pointer Language (XPointer)" (http://www.w3.org/TR/1998/WD-xptr-19980303). @@ -230,15 +230,33 @@

attributes ?attributeNamePattern?
-
Returns all attributes matching the attributeNamePattern. -If attributeNamePattern isn't given, all attributes are returned as a Tcl -list.
+
Returns information about the attriubtes matching the + attributeNamePattern. If attributeNamePattern + isn't given, information about all attributes are returned. + The return value is a Tcl list, the elements just the + attriubute name in case of non namespaced attriubtes and three + element sublists for namespaced attributes. n case of an + "ordinary" namespaced attribute, the sublist elements are + {<localname> <prefix> <namespace_uri>}. In the special case of + an xml namespace declaration it is {<the prefix defined> + <localname> ""}. +
+ +
+attributeNames ?attributeNamePattern? +
+
Returns a flat list of all attributes names (as found in + the XML source) matching the attributeNamePattern. If + attributeNamePattern isn't given, all attribute names + are returned as a Tcl list.
+ +
appendChild newChild
Appends newChild to the end of the child list of the @@ -734,16 +752,16 @@

Otherwise, if an unknown method name is given, the command with the same name as the given method within the namespace ::dom::domNode is tried to be executed. This allows quick method additions on Tcl level.

-

SEE ALSO

dom, domDoc

+

SEE ALSO

dom, domDoc

-

KEYWORDS

+

KEYWORDS

XML, DOM, document, node, parsing

Index: doc/domNode.n ================================================================== --- doc/domNode.n +++ doc/domNode.n @@ -317,13 +317,26 @@ \&\fB\fBremoveAttributeNS\fP \fIuri\fB \fIlocalName\fB \&\fRRemoves the attribute with the local name \fIlocalName\fR within the namespace \fIuri\fR. .TP \&\fB\fBattributes\fP \fB?attributeNamePattern?\fP -\&\fRReturns all attributes matching the \fIattributeNamePattern\fR. -If \fIattributeNamePattern\fR isn't given, all attributes are returned as a Tcl -list. +\&\fRReturns information about the attriubtes matching the +\&\fIattributeNamePattern\fR. If \fIattributeNamePattern\fR +isn't given, information about all attributes are returned. +The return value is a Tcl list, the elements just the +attriubute name in case of non namespaced attriubtes and three +element sublists for namespaced attributes. n case of an +"ordinary" namespaced attribute, the sublist elements are +{ }. In the special case of +an xml namespace declaration it is { + ""}. +.TP +\&\fB\fBattributeNames\fP \fB?attributeNamePattern?\fP +\&\fRReturns a flat list of all attributes names (as found in +the XML source) matching the \fIattributeNamePattern\fR. If +\&\fIattributeNamePattern\fR isn't given, all attribute names +are returned as a Tcl list. .TP \&\fB\fBappendChild\fP \fInewChild\fB \&\fRAppends \fInewChild\fR to the end of the child list of the node. .TP Index: doc/domNode.xml ================================================================== --- doc/domNode.xml +++ doc/domNode.xml @@ -208,15 +208,31 @@ the namespace uri. attributes - Returns all attributes matching the attributeNamePattern. -If attributeNamePattern isn't given, all attributes are returned as a Tcl -list. + Returns information about the attriubtes matching the + attributeNamePattern. If attributeNamePattern + isn't given, information about all attributes are returned. + The return value is a Tcl list, the elements just the + attriubute name in case of non namespaced attriubtes and three + element sublists for namespaced attributes. n case of an + "ordinary" namespaced attribute, the sublist elements are + {<localname> <prefix> <namespace_uri>}. In the special case of + an xml namespace declaration it is {<the prefix defined> + <localname> ""}. + + + attributeNames + Returns a flat list of all attributes names (as found in + the XML source) matching the attributeNamePattern. If + attributeNamePattern isn't given, all attribute names + are returned as a Tcl list. + + appendChild newChild Appends newChild to the end of the child list of the node. Index: generic/tcldom.c ================================================================== --- generic/tcldom.c +++ generic/tcldom.c @@ -305,10 +305,11 @@ " hasAttributeNS uri localName \n" " getAttributeNS uri localName ?defaultValue? \n" " setAttributeNS uri attrName value ?attrName value ...? \n" " removeAttributeNS uri attrName \n" " attributes ?attrNamePattern? \n" + " attributeNames ?attrNamePattern? \n" " appendChild new \n" " insertBefore new ref \n" " replaceChild new old \n" " removeChild child \n" " cloneNode ?-deep? \n" @@ -4381,11 +4382,11 @@ "asHTML", "prefix", "getBaseURI", "appendFromScript", "xslt", "toXPath", "delete", "getElementById", "getElementsByTagName", "getElementsByTagNameNS", "disableOutputEscaping", "precedes", "asText", "insertBeforeFromScript", "normalize", "baseURI", - "asJSON", "jsonType", + "asJSON", "jsonType", "attributeNames", #ifdef TCL_THREADS "readlock", "writelock", #endif NULL }; @@ -4404,11 +4405,11 @@ m_asHTML, m_prefix, m_getBaseURI, m_appendFromScript, m_xslt, m_toXPath, m_delete, m_getElementById, m_getElementsByTagName, m_getElementsByTagNameNS, m_disableOutputEscaping, m_precedes, m_asText, m_insertBeforeFromScript, m_normalize, m_baseURI, - m_asJSON, m_jsonType + m_asJSON, m_jsonType, m_attributeNames #ifdef TCL_THREADS ,m_readlock, m_writelock #endif }; @@ -4649,10 +4650,37 @@ namePtr); if (result != TCL_OK) { Tcl_DecrRefCount(namePtr); return result; } + } + attrs = attrs->nextSibling; + } + break; + + case m_attributeNames: + CheckArgs(2,3,2,"?nameFilter?"); + if (node->nodeType != ELEMENT_NODE) { + SetResult(""); + return TCL_OK; + } + filter = NULL; + if (objc == 3) { + filter = Tcl_GetString(objv[2]); + } + resultPtr = Tcl_GetObjResult(interp); + + attrs = node->firstAttr; + while (attrs != NULL) { + if (!filter || Tcl_StringMatch((char*)attrs->nodeName, filter)) { + namePtr = Tcl_NewStringObj((char*)attrs->nodeName, -1); + result = Tcl_ListObjAppendElement(interp, resultPtr, + namePtr); + if (result != TCL_OK) { + Tcl_DecrRefCount(namePtr); + return result; + } } attrs = attrs->nextSibling; } break; Index: tests/domNode.test ================================================================== --- tests/domNode.test +++ tests/domNode.test @@ -19,11 +19,11 @@ # domNode-13.*: appendFromScript # domNode-14.*: appendFromList # domNode-15.*: delete # domNode-16.*: getAttribute # domNode-17.*: nodeType -# domNode-18.*: attributes +# domNode-18.*: attributes, attributeNames # domNode-19.*: removeAttribute, removeAttributeNS # domNode-20.*: parentNode # domNode-21.*: hasChildNodes # domNode-22.*: localName, prefix # domNode-23.*: replaceChild @@ -1998,10 +1998,38 @@ } {} test domNode-18.7 {attributes} { [$root firstChild] attributes } {} + +test domNode-18.1.1 {attributeNames} { + $root attributeNames +} {xmlns:foo attr1 attr2 attr3 foo:attr1 worble2} + +test domNode-18.2.1 {attributeNames} { + $root attributeNames * +} {xmlns:foo attr1 attr2 attr3 foo:attr1 worble2} + +test domNode-18.3.1 {attributeNames} { + $root attributeNames attr* +} {attr1 attr2 attr3} + +test domNode-18.4.1 {attributeNames} { + $root attributeNames *2* +} {attr2 worble2} + +test domNode-18.5.1 {attributeNames} { + $root attributeNames worble2 +} {worble2} + +test domNode-18.6.1 {attributeNames} { + $root attributeNames *brab* +} {} + +test domNode-18.7.1 {attributeNames} { + [$root firstChild] attributeNames +} {} # Hmmm. This two following tests are mostly there to document the # behavior of the method, as it is. It may debatable if they should # behave this way. The optional attribute name pattern is a tDOM # DOM extension there is nothing in the rec, which could help to argue. @@ -2012,10 +2040,14 @@ } {} test domNode-18.9 {attributes} { $root attributes foo* } {{attr1 foo http://tdom.org/ns}} + +test domNode-18.9.1 {attributeNames} { + $root attributeNames foo:* +} {foo:attr1} $doc delete set doc [dom parse {