Count the no of elements in an XML node
require 'rexml/document' include REXML file = File.new('test.xml') doc = Document.new(file) puts doc.root.elements.to_a.length
11304 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
require 'rexml/document' include REXML file = File.new('test.xml') doc = Document.new(file) puts doc.root.elements.to_a.length
$sql = "SELECT * FROM {node} n WHERE type = 'blog' AND status = 1 ORDER BY n.created DESC" $result = pager_query(db_rewrite_sql($sql), 0, 10); while ($data = db_fetch_object($result)) { $node = node_load($data->nid); print node_view($node, TRUE); } // Add links to remaining pages of results. print theme('pager', NULL, 10);
import _String; dynamic class _XML extends XML { function _XML() { } public function $N(tag,xmlNode,xmlNodeArray){ if (xmlNode == undefined) var xmlNode = this; if (xmlNodeArray == undefined) var xmlNodeArray:Array = new Array(); var nodeArray:Array = new Array(); for (var x=0; x<xmlNode.childNodes.length; x++) { if (xmlNode.childNodes[x].nodeType == 1){ if (xmlNode.childNodes[x].nodeName == tag) xmlNodeArray.push(xmlNode.childNodes[x]); $N(tag,xmlNode.childNodes[x],xmlNodeArray); } } return xmlNodeArray; } // If multiple, returns a nodeValue Array // If single, returns a nodeValue String public function $V(tag,xmlNode) { if (xmlNode == undefined) var xmlNode = this; var n = $N(tag,xmlNode); if (n.length == 1){ var nV = n[0].firstChild.nodeValue; if (nV != undefined){ nV = escape(nV); nV = _String.Replace(nV,"%C2%93","%22"); nV = _String.Replace(nV,"%C2%94","%22"); nV = unescape(nV); } return nV; } else { var vArray:Array = new Array(); for (var i:String in n) { vArray[i] = n[i].firstChild.nodeValue; if (vArray[i] != undefined){ vArray[i] = escape(vArray[i]); vArray[i] = _String.Replace(vArray[i],"%C2%93","%22"); vArray[i] = _String.Replace(vArray[i],"%C2%94","%22"); vArray[i] = unescape(vArray[i]); } } return vArray; } } }