xml-8.1.tcl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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 ;
00057
00058
00059
00060 variable xmlnsNS http:
00061
00062
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
00111
00112
00113
00114
00115
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