xml-8.1.tcl

Go to the documentation of this file.
00001 /*  xml.tcl --*/
00002 /* */
00003 /*  This file provides generic XML services for all implementations.*/
00004 /*  This file supports Tcl 8.1 regular expressions.*/
00005 /* */
00006 /*  See tclparser.tcl for the Tcl implementation of a XML parser.*/
00007 /* */
00008 /*  Copyright (c) 2005 by Explain.*/
00009 /*  http://www.explain.com.au/*/
00010 /*  Copyright (c) 1998-2004 Zveno Pty Ltd*/
00011 /*  http://www.zveno.com/*/
00012 /*  */
00013 /*  See the file "LICENSE" in this distribution for information on usage and*/
00014 /*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.*/
00015 /* */
00016 /*  $Id: xml-8.1.tcl,v 1.16.2.1 2005/12/28 06:49:51 balls Exp $*/
00017 
00018 package require Tcl 8.1
00019 
00020 package provide xmldefs 3.2
00021 
00022 package require sgml 1.8
00023 
00024 namespace xml {
00025 
00026     namespace export qnamesplit
00027 
00028     /*  Convenience routine*/
00029     ret  cl x (
00030     type return "\[$, type x\]"
00031     )
00032 
00033     # Define various regular expressions
00034 
00035     # Characters
00036     variable Char $::sgml::Char
00037 
00038     # white space
00039     variable Wsp " \t\r\n"
00040     variable allWsp [cl $Wsp]*
00041     variable noWsp [cl ^$Wsp]
00042 
00043     # Various XML names and tokens
00044 
00045     variable NameChar $::sgml::NameChar
00046     variable Name $::sgml::Name
00047     variable Names $::sgml::Names
00048     variable Nmtoken $::sgml::Nmtoken
00049     variable Nmtokens $::sgml::Nmtokens
00050 
00051     # XML Namespaces names
00052 
00053     # NCName ::= Name - ':'
00054     variable NCName $::sgml::Name
00055     regsub -all : $NCName {} NCName
00056     variable QName (${NCName}:)?$NCName     ;/*  (Prefix ':')? LocalPart*/
00057 
00058     /*  The definition of the Namespace URI for XML Namespaces themselves.*/
00059     /*  The prefix 'xml' is automatically bound to this URI.*/
00060     variable xmlnsNS http://www.w3.org/XML/1998/namespace
00061 
00062     /*  table of predefined entities*/
00063 
00064     variable EntityPredef
00065     array  EntityPredef =  {
00066     lt <   gt >   amp &   quot \"   apos '
00067     }
00068 
00069     /*  Expressions for pulling things apart*/
00070     variable tokExpr <(/?)([::xml::cl ^$::xml::Wsp>/]+)([::xml::cl $::xml::Wsp]*[::xml::cl ^>]*)>
00071     variable substExpr "\}\n{\\2} {\\1} {\\3} \{"
00072 
00073 }
00074 
00075 /* */
00076 /*  Exported procedures*/
00077 /* */
00078 
00079 /*  xml::qnamesplit --*/
00080 /* */
00081 /*  Split a QName into its constituent parts:*/
00082 /*  the XML Namespace prefix and the Local-name*/
00083 /* */
00084 /*  Arguments:*/
00085 /*  qname   XML Qualified Name (see XML Namespaces [6])*/
00086 /* */
00087 /*  Results:*/
00088 /*  Returns prefix and local-name as a Tcl list.*/
00089 /*  Error condition returned if the prefix or local-name*/
00090 /*  are not valid NCNames (XML Name)*/
00091 
00092 ret  xml::qnamesplit qname (
00093     type variable , type NCName
00094     , type variable , type Name
00095 
00096     , type set , type prefix , optional 
00097     , type set , type localname $, type qname
00098     , type if , optional [regexp =: $qname] , optional 
00099     if ={![regexp ^($NCName)?:($NCName)\$ =$qname discard =prefix localname] , optional 
00100         return =-code error ="name \"$qname\" =is not =a valid =QName"
00101     
00102     ) elseif {![regexp ^$Name\$ $qname]} {
00103     return -code error "name \"$qname\" is not a valid Name"
00104     }
00105 
00106     return [list $prefix $localname]
00107 }
00108 
00109 /* */
00110 /*  General utility procedures*/
00111 /* */
00112 
00113 /*  xml::noop --*/
00114 /* */
00115 /*  A do-nothing proc*/
00116 
00117 ret  xml::noop args ()
00118 
00119 ### Following procedures are based on html_library
00120 
00121 # xml::zapWhite --
00122 #
00123 #   Convert multiple white space into a single space.
00124 #
00125 # Arguments:
00126 #   data    plain text
00127 #
00128 # Results:
00129 #   As above
00130 
00131 proc xml::zapWhite data {
00132     regsub -all "\[ \t\r\n\]+" $data { } data
00133     return $data
00134 }
00135 
00136 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1