📄 xml.htm
字号:
<FONT color='gray'>155| </FONT> <FONT color='darkblue'><B>var</B></FONT> a <FONT color='dimgray'>=</FONT> el<FONT color='dimgray'>[</FONT>att_name<FONT color='dimgray'>]</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>156| </FONT> <FONT color='darkblue'><B>if</B></FONT><FONT color='dimgray'>(</FONT> a <FONT color='dimgray'>)</FONT> r<FONT color='dimgray'>[</FONT>a<FONT color='dimgray'>]</FONT> <FONT color='dimgray'>=</FONT> el<FONT color='dimgray'>;</FONT>
<FONT color='gray'>157| </FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'>158| </FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'>159| </FONT> <FONT color='dimgray'>}</FONT> <FONT color='darkblue'><B>else</B></FONT> <FONT color='dimgray'>{</FONT> <FONT color='green'>// array</FONT>
<FONT color='gray'>160| </FONT> r <FONT color='dimgray'>=</FONT> <FONT color='darkblue'><B>new</B></FONT> <FONT color='purple'>array</FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>161| </FONT> <FONT color='darkblue'><B>if</B></FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>!</FONT>_value<FONT color='dimgray'>)</FONT> <FONT color='darkblue'><B>return</B></FONT> r<FONT color='dimgray'>;</FONT>
<FONT color='gray'>162| </FONT> <FONT color='darkblue'><B>var</B></FONT> i<FONT color='dimgray'>;</FONT>
<FONT color='gray'>163| </FONT> <FONT color='darkblue'><B>for</B></FONT><FONT color='dimgray'>(</FONT>i <FONT color='dimgray'>=</FONT> <FONT color='red'>0</FONT><FONT color='dimgray'>;</FONT> i <FONT color='dimgray'><</FONT> _value<FONT color='dimgray'>.</FONT>length<FONT color='dimgray'>;</FONT> i<FONT color='dimgray'>++</FONT><FONT color='dimgray'>)</FONT>
<FONT color='gray'>164| </FONT> <FONT color='dimgray'>{</FONT>
<FONT color='gray'>165| </FONT> <FONT color='darkblue'><B>var</B></FONT> el <FONT color='dimgray'>=</FONT> _value<FONT color='dimgray'>[</FONT>i<FONT color='dimgray'>]</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>166| </FONT> <FONT color='darkblue'><B>if</B></FONT><FONT color='dimgray'>(</FONT> el instanceof simple_element <FONT color='dimgray'>&&</FONT> el<FONT color='dimgray'>.</FONT>_name<FONT color='dimgray'>.</FONT><FONT color='purple'>like</FONT><FONT color='dimgray'>(</FONT>tag_name<FONT color='dimgray'>)</FONT><FONT color='dimgray'>)</FONT>
<FONT color='gray'>167| </FONT> r<FONT color='dimgray'>.</FONT><FONT color='purple'>push</FONT><FONT color='dimgray'>(</FONT>el<FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>168| </FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'>169| </FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'>170| </FONT> <FONT color='darkblue'><B>return</B></FONT> r<FONT color='dimgray'>;</FONT>
<FONT color='gray'>171| </FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'>172| </FONT> <FONT color='darkblue'><B>function</B></FONT> <FONT color='purple'>valueToString</FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>)</FONT> <FONT color='dimgray'>{</FONT>
<FONT color='gray'>173| </FONT> <FONT color='darkblue'><B>if</B></FONT><FONT color='dimgray'>(</FONT>_value<FONT color='dimgray'>)</FONT>
<FONT color='gray'>174| </FONT> <FONT color='dimgray'>{</FONT>
<FONT color='gray'>175| </FONT> <FONT color='darkblue'><B>var</B></FONT> i<FONT color='dimgray'>,</FONT>v <FONT color='dimgray'>=</FONT> <FONT color='maroon'>""</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>176| </FONT> <FONT color='darkblue'><B>for</B></FONT><FONT color='dimgray'>(</FONT>i <FONT color='dimgray'>=</FONT> <FONT color='red'>0</FONT><FONT color='dimgray'>;</FONT> i <FONT color='dimgray'><</FONT> _value<FONT color='dimgray'>.</FONT>length<FONT color='dimgray'>;</FONT> i<FONT color='dimgray'>++</FONT><FONT color='dimgray'>)</FONT>
<FONT color='gray'>177| </FONT> v <FONT color='dimgray'>+=</FONT> <FONT color='purple'>is_string</FONT><FONT color='dimgray'>(</FONT>_value<FONT color='dimgray'>[</FONT>i<FONT color='dimgray'>]</FONT><FONT color='dimgray'>)</FONT>? <FONT color='purple'>unescape</FONT><FONT color='dimgray'>(</FONT>_value<FONT color='dimgray'>[</FONT>i<FONT color='dimgray'>]</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>:</FONT> <FONT color='purple'>string</FONT><FONT color='dimgray'>(</FONT>_value<FONT color='dimgray'>[</FONT>i<FONT color='dimgray'>]</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>178| </FONT> <FONT color='darkblue'><B>return</B></FONT> v<FONT color='dimgray'>;</FONT>
<FONT color='gray'>179| </FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'>180| </FONT> <FONT color='darkblue'><B>return</B></FONT> <FONT color='maroon'>""</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>181| </FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'>182| </FONT><FONT color='dimgray'>}</FONT>
<FONT color='gray'>183| </FONT>
<FONT color='gray'>184| </FONT>
<FONT color='gray'>185| </FONT><FONT color='green'>//|</FONT>
<FONT color='gray'>186| </FONT><FONT color='green'>//| idee fixe</FONT>
<FONT color='gray'>187| </FONT><FONT color='green'>//|</FONT>
<FONT color='gray'>188| </FONT><FONT color='darkblue'><B>class</B></FONT> parser <FONT color='dimgray'>{</FONT>
<FONT color='gray'>189| </FONT> <FONT color='darkblue'><B>var</B></FONT> _in<FONT color='dimgray'>;</FONT>
<FONT color='gray'>190| </FONT> <FONT color='darkblue'><B>var</B></FONT> _error_msg<FONT color='dimgray'>;</FONT>
<FONT color='gray'>191| </FONT> <FONT color='darkblue'><B>var</B></FONT> _error_ln<FONT color='dimgray'>;</FONT>
<FONT color='gray'>192| </FONT> <FONT color='darkblue'><B>var</B></FONT> _got_eot<FONT color='dimgray'>;</FONT>
<FONT color='gray'>193| </FONT><FONT color='green'>// vocabulary for interning nmtokens</FONT>
<FONT color='gray'>194| </FONT> <FONT color='darkblue'><B>static</B></FONT> <FONT color='darkblue'><B>var</B></FONT> voc <FONT color='dimgray'>=</FONT> <FONT color='darkblue'><B>new</B></FONT> <FONT color='purple'>map</FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>195| </FONT>
<FONT color='gray'>196| </FONT> <FONT color='darkblue'><B>function</B></FONT> <FONT color='purple'>parser</FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>)</FONT> <FONT color='dimgray'>{</FONT> _in <FONT color='dimgray'>=</FONT> <FONT color='darkblue'><B>null</B></FONT><FONT color='dimgray'>;</FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'>197| </FONT>
<FONT color='gray'>198| </FONT> <FONT color='darkblue'><B>function</B></FONT> <FONT color='purple'>intern</FONT><FONT color='dimgray'>(</FONT>nmtoken<FONT color='dimgray'>)</FONT> <FONT color='dimgray'>{</FONT>
<FONT color='gray'>199| </FONT> <FONT color='darkblue'><B>if</B></FONT><FONT color='dimgray'>(</FONT> <FONT color='dimgray'>!</FONT>voc<FONT color='dimgray'>.</FONT><FONT color='purple'>exist</FONT><FONT color='dimgray'>(</FONT>nmtoken<FONT color='dimgray'>)</FONT> <FONT color='dimgray'>)</FONT> voc<FONT color='dimgray'>[</FONT>nmtoken<FONT color='dimgray'>]</FONT> <FONT color='dimgray'>=</FONT> nmtoken<FONT color='dimgray'>;</FONT>
<FONT color='gray'>200| </FONT> <FONT color='darkblue'><B>return</B></FONT> voc<FONT color='dimgray'>[</FONT>nmtoken<FONT color='dimgray'>]</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>201| </FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'>202| </FONT>
<FONT color='gray'>203| </FONT> <FONT color='darkblue'><B>function</B></FONT> <FONT color='purple'>compile_atts</FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>)</FONT> <FONT color='dimgray'>{</FONT>
<FONT color='gray'>204| </FONT> <FONT color='darkblue'><B>var</B></FONT> atts<FONT color='dimgray'>;</FONT>
<FONT color='gray'>205| </FONT> <FONT color='darkblue'><B>while</B></FONT><FONT color='dimgray'>(</FONT><FONT color='darkblue'><B>true</B></FONT><FONT color='dimgray'>)</FONT> <FONT color='dimgray'>{</FONT>
<FONT color='gray'>206| </FONT> <FONT color='darkblue'><B>var</B></FONT> n <FONT color='dimgray'>=</FONT> _in<FONT color='dimgray'>.</FONT><FONT color='purple'>get</FONT><FONT color='dimgray'>(</FONT><FONT color='maroon'>'='</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>"/>"</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>">"</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>.</FONT><FONT color='purple'>trim</FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>207| </FONT> <FONT color='darkblue'><B>if</B></FONT><FONT color='dimgray'>(</FONT>_in<FONT color='dimgray'>.</FONT>get_match <FONT color='dimgray'>==</FONT> <FONT color='red'>2</FONT><FONT color='dimgray'>)</FONT> _got_eot <FONT color='dimgray'>=</FONT> <FONT color='darkblue'><B>true</B></FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>208| </FONT> <FONT color='darkblue'><B>if</B></FONT><FONT color='dimgray'>(</FONT>_in<FONT color='dimgray'>.</FONT>get_match <FONT color='dimgray'>!=</FONT> <FONT color='red'>1</FONT><FONT color='dimgray'>)</FONT> <FONT color='darkblue'><B>break</B></FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>209| </FONT>
<FONT color='gray'>210| </FONT> <FONT color='darkblue'><B>if</B></FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>!</FONT>n<FONT color='dimgray'>)</FONT> <FONT color='darkblue'><B>throw</B></FONT> <FONT color='maroon'>"empty name encountered"</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>211| </FONT>
<FONT color='gray'>212| </FONT> <FONT color='darkblue'><B>var</B></FONT> z <FONT color='dimgray'>=</FONT> _in<FONT color='dimgray'>.</FONT><FONT color='purple'>get</FONT><FONT color='dimgray'>(</FONT><FONT color='maroon'>'\"'</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>'\''</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>"/>"</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>">"</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>.</FONT><FONT color='purple'>trim</FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>213| </FONT> <FONT color='darkblue'><B>if</B></FONT><FONT color='dimgray'>(</FONT> z <FONT color='dimgray'>)</FONT> <FONT color='darkblue'><B>throw</B></FONT> string<FONT color='dimgray'>::</FONT><FONT color='purple'>printf</FONT><FONT color='dimgray'>(</FONT><FONT color='maroon'>"bad attribute definition (%s)"</FONT><FONT color='dimgray'>,</FONT> n <FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>214| </FONT> <FONT color='darkblue'><B>if</B></FONT><FONT color='dimgray'>(</FONT>_in<FONT color='dimgray'>.</FONT>get_match <FONT color='dimgray'>></FONT> <FONT color='red'>2</FONT><FONT color='dimgray'>)</FONT> <FONT color='darkblue'><B>throw</B></FONT> <FONT color='maroon'>"empty value encountered"</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>215| </FONT> <FONT color='darkblue'><B>var</B></FONT> v <FONT color='dimgray'>=</FONT> _in<FONT color='dimgray'>.</FONT><FONT color='purple'>get</FONT><FONT color='dimgray'>(</FONT> _in<FONT color='dimgray'>.</FONT>get_match <FONT color='dimgray'>==</FONT> <FONT color='red'>1</FONT> ? <FONT color='maroon'>'\"'</FONT> <FONT color='dimgray'>:</FONT> <FONT color='maroon'>'\''</FONT> <FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>216| </FONT> <FONT color='darkblue'><B>if</B></FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>!</FONT>atts<FONT color='dimgray'>)</FONT> atts <FONT color='dimgray'>=</FONT> <FONT color='darkblue'><B>new</B></FONT> <FONT color='purple'>map</FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>217| </FONT> atts<FONT color='dimgray'>[</FONT> <FONT color='purple'>intern</FONT><FONT color='dimgray'>(</FONT>n<FONT color='dimgray'>)</FONT> <FONT color='dimgray'>]</FONT> <FONT color='dimgray'>=</FONT> <FONT color='purple'>unescape</FONT><FONT color='dimgray'>(</FONT>v<FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>218| </FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'>219| </FONT> <FONT color='darkblue'><B>return</B></FONT> atts<FONT color='dimgray'>;</FONT>
<FONT color='gray'>220| </FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'>221| </FONT>
<FONT color='gray'>222| </FONT> <FONT color='darkblue'><B>function</B></FONT> <FONT color='purple'>compile_tag</FONT><FONT color='dimgray'>(</FONT>tag_name<FONT color='dimgray'>)</FONT>
<FONT color='gray'>223| </FONT> <FONT color='dimgray'>{</FONT>
<FONT color='gray'>224| </FONT> <FONT color='green'>//NB already got '<'</FONT>
<FONT color='gray'>225| </FONT> <FONT color='darkblue'><B>var</B></FONT> c <FONT color='dimgray'>=</FONT> _in<FONT color='dimgray'>.</FONT><FONT color='purple'>get</FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT> <FONT color='green'>// get one char</FONT>
<FONT color='gray'>226| </FONT> <FONT color='darkblue'><B>switch</B></FONT><FONT color='dimgray'>(</FONT>c<FONT color='dimgray'>)</FONT>
<FONT color='gray'>227| </FONT> <FONT color='dimgray'>{</FONT>
<FONT color='gray'>228| </FONT> <FONT color='darkblue'><B>case</B></FONT> <FONT color='maroon'>'/'</FONT><FONT color='dimgray'>:</FONT>
<FONT color='gray'>229| </FONT> <FONT color='dimgray'>{</FONT>
<FONT color='gray'>230| </FONT> <FONT color='darkblue'><B>var</B></FONT> n <FONT color='dimgray'>=</FONT> _in<FONT color='dimgray'>.</FONT><FONT color='purple'>get</FONT><FONT color='dimgray'>(</FONT><FONT color='maroon'>'>'</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>.</FONT><FONT color='purple'>trim</FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT> <FONT color='green'>// get until (exclusive) </FONT>
<FONT color='gray'>231| </FONT> <FONT color='darkblue'><B>if</B></FONT><FONT color='dimgray'>(</FONT>tag_name <FONT color='dimgray'>!=</FONT> n<FONT color='dimgray'>)</FONT> <FONT color='darkblue'><B>throw</B></FONT> string<FONT color='dimgray'>::</FONT><FONT color='purple'>printf</FONT><FONT color='dimgray'>(</FONT><FONT color='maroon'>"tag '%s' not closed (%s)"</FONT><FONT color='dimgray'>,</FONT>tag_name<FONT color='dimgray'>,</FONT>n<FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>232| </FONT> <FONT color='darkblue'><B>return</B></FONT> <FONT color='darkblue'><B>null</B></FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'>233| </FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'>234| </FONT> <FONT color='darkblue'><B>case</B></FONT> <FONT color='maroon'>'?'</FONT><FONT color='dimgray'>:</FONT>
<FONT color='gray'>235| </FONT> <FONT color='dimgray'>{</FONT>
<FONT color='gray'>236| </FONT> <FONT color='darkblue'><B>var</B></FONT> v <FONT color='dimgray'>=</FONT> _in<FONT color='dimgray'>.</FONT><FONT color='purple'>get</FONT><FONT color='dimgray'>(</FONT><FONT color='maroon'>"?>"</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -