Subject: Re: Another hopefully simple question: root attributes From: Norman Gray <norman@xxxxxxxxxxxxxxx> Date: Wed, 27 Oct 1999 16:56:59 +0100 (BST) |
Greetings, On Wed, 27 Oct 1999, Wroth, Mark wrote: > I need a construct which returns as a string the value of a known attribute > of the root element of a document (regardless of the GI of the document > element). I think my problem is in identifying the root element, but ... By `root element' do you mean the document element (of arbitrary GI)? The root of the grove is not the same as the document element, and though it has (grove) properties, it doesn't have (SGML) attributes. The code I've appended below returns the document-element based on an arbitrary element within the grove. There's nothing particularly original in the code, but the comments attached to it might possibly be useful -- they summarise what I understand about this. > Say the attribute I need is "id" (which it is :-). As I read the spec, > > (attribute-string "id" root) You'd use this as (attribute-string "id" (document-element (current-node))) Here's the code: <routine> <routinename>document-element <description> <p>Returns the document element of the document containing the given node. <p>Only the <code/SgmlDocument/ node class exibits a <code/DocumentElement/ property, so to find the document element we first have to find the grove root, which we do by examining the <code/grove-root/ property of the current node. The only node which doesn't have a <code/grove-root/ property (so that the <funcname/node-property/ routine will correctly return <code/#f/ -- ie, it exhibits the property, but with the value <code/#f/) is the root node, but in that case, <funcname/current-node/ returns the grove root directly (this isn't clear from the standard -- see the discussion on `Finding the root element' in the dssslist archive at <url>http://www.mulberrytech.com/dsssl/dssslist/</url>). <p>The subsequent calls to <funcname/node-property/ default <code/#f/ if the property is not exhibited by the node. This catches the case where the grove root doesn't have any <code/document-element/ property, for example if the grove is malformed because it resulted from a call to <funcname/sgml-parse/ with a non-existent file. <returnvalue type="singleton-node-list">The document element, or <code/#f/ if not found. <argumentlist> <parameter optional default='(current-node)'> <name>node <type>node-list <description>this node indicates the grove we want the document element of. <codebody> (define (document-element #!optional (node (current-node))) (let ((gr (node-property 'grove-root node))) (if gr ; gr is the grove root (node-property 'document-element gr default: #f) ;; else we're in the root rule now (node-property 'document-element node default: #f)))) I hope this helps. All the best, Norman --------------------------------------------------------------------------- Norman Gray http://www.astro.gla.ac.uk/users/norman/ Physics and Astronomy, University of Glasgow, UK norman@xxxxxxxxxxxxxxx DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Another hopefully simple questi, Brandon Ibach | Thread | RE: Another hopefully simple questi, Wroth, Mark |
Re: Another hopefully simple questi, Brandon Ibach | Date | RE: Another hopefully simple questi, Wroth, Mark |
Month |