123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662 |
- <?xml version="1.0" encoding="utf-8" ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <!-- This file is generated by Nim. -->
- <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>std/parsexml</title>
- <!-- Google fonts -->
- <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
- <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
- <!-- Favicon -->
- <link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
- <link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
- <!-- CSS -->
- <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
- <!-- JS -->
- <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
- </head>
- <body>
- <div class="document" id="documentId">
- <div class="container">
- <h1 class="title">std/parsexml</h1>
- <div class="row">
- <div class="three columns">
- <div class="theme-select-wrapper">
- <label for="theme-select">Theme: </label>
- <select id="theme-select" onchange="setTheme(this.value)">
- <option value="auto">🌗 Match OS</option>
- <option value="dark">🌑 Dark</option>
- <option value="light">🌕 Light</option>
- </select>
- </div>
- <div id="global-links">
- <ul class="simple-boot">
- <li><a href="manual.html">Manual</a></li>
- <li><a href="lib.html">Standard library</a></li>
- <li> <a id="indexLink" href="theindex.html">Index</a></li>
- <li><a href="compiler/theindex.html">Compiler docs</a></li>
- <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
- <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
- </ul>
- </div>
- <div id="searchInputDiv">
- Search: <input type="search" id="searchInput"
- oninput="search()" />
- </div>
-
- <ul class="simple simple-toc" id="toc-list">
- <li><a class="reference" id="example-1colon-retrieve-html-title_toc" href="#example-1colon-retrieve-html-title">Example 1: Retrieve HTML title</a></li>
- <li><a class="reference" id="example-2colon-retrieve-all-html-links_toc" href="#example-2colon-retrieve-all-html-links">Example 2: Retrieve all HTML links</a></li>
- <li>
- <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
- <ul class="simple simple-toc-section">
- <li><a class="reference" href="#XmlErrorKind" title="XmlErrorKind = enum
- errNone, ## no error
- errEndOfCDataExpected, ## ``]]>`` expected
- errNameExpected, ## name expected
- errSemicolonExpected, ## ``;`` expected
- errQmGtExpected, ## ``?>`` expected
- errGtExpected, ## ``>`` expected
- errEqExpected, ## ``=`` expected
- errQuoteExpected, ## ``"`` or ``'`` expected
- errEndOfCommentExpected, ## ``-->`` expected
- errAttributeValueExpected ## non-empty attribute value expected">XmlErrorKind</a></li>
- <li><a class="reference" href="#XmlEventKind" title="XmlEventKind = enum
- xmlError, ## an error occurred during parsing
- xmlEof, ## end of file reached
- xmlCharData, ## character data
- xmlWhitespace, ## whitespace has been parsed
- xmlComment, ## a comment has been parsed
- xmlPI, ## processing instruction (``<?name something ?>``)
- xmlElementStart, ## ``<elem>``
- xmlElementEnd, ## ``</elem>``
- xmlElementOpen, ## ``<elem
- xmlAttribute, ## ``key = "value"`` pair
- xmlElementClose, ## ``>``
- xmlCData, ## ``<![CDATA[`` ... data ... ``]]>``
- xmlEntity, ## &entity;
- xmlSpecial ## ``<! ... data ... >``">XmlEventKind</a></li>
- <li><a class="reference" href="#XmlParseOption" title="XmlParseOption = enum
- reportWhitespace, ## report whitespace
- reportComments, ## report comments
- allowUnquotedAttribs, ## allow unquoted attribute values (for HTML)
- allowEmptyAttribs ## allow empty attributes (without explicit value)">XmlParseOption</a></li>
- <li><a class="reference" href="#XmlParser" title="XmlParser = object of BaseLexer">XmlParser</a></li>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">close
- <li><a class="reference" href="#close%2CXmlParser" title="close(my: var XmlParser)">close(my: var XmlParser)</a></li>
- </ul>
- <ul class="simple nested-toc-section">errorMsg
- <li><a class="reference" href="#errorMsg%2CXmlParser" title="errorMsg(my: XmlParser): string">errorMsg(my: XmlParser): string</a></li>
- <li><a class="reference" href="#errorMsg%2CXmlParser%2Cstring" title="errorMsg(my: XmlParser; msg: string): string">errorMsg(my: XmlParser; msg: string): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">errorMsgExpected
- <li><a class="reference" href="#errorMsgExpected%2CXmlParser%2Cstring" title="errorMsgExpected(my: XmlParser; tag: string): string">errorMsgExpected(my: XmlParser; tag: string): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">getColumn
- <li><a class="reference" href="#getColumn%2CXmlParser" title="getColumn(my: XmlParser): int">getColumn(my: XmlParser): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">getFilename
- <li><a class="reference" href="#getFilename%2CXmlParser" title="getFilename(my: XmlParser): string">getFilename(my: XmlParser): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">getLine
- <li><a class="reference" href="#getLine%2CXmlParser" title="getLine(my: XmlParser): int">getLine(my: XmlParser): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">kind
- <li><a class="reference" href="#kind%2CXmlParser" title="kind(my: XmlParser): XmlEventKind">kind(my: XmlParser): XmlEventKind</a></li>
- </ul>
- <ul class="simple nested-toc-section">next
- <li><a class="reference" href="#next%2CXmlParser" title="next(my: var XmlParser)">next(my: var XmlParser)</a></li>
- </ul>
- <ul class="simple nested-toc-section">open
- <li><a class="reference" href="#open%2CXmlParser%2CStream%2Cstring%2Cset%5BXmlParseOption%5D" title="open(my: var XmlParser; input: Stream; filename: string;
- options: set[XmlParseOption] = {})">open(my: var XmlParser; input: Stream; filename: string;
- options: set[XmlParseOption] = {})</a></li>
- </ul>
- <ul class="simple nested-toc-section">rawData
- <li><a class="reference" href="#rawData%2CXmlParser" title="rawData(my: var XmlParser): lent string">rawData(my: var XmlParser): lent string</a></li>
- </ul>
- <ul class="simple nested-toc-section">rawData2
- <li><a class="reference" href="#rawData2%2CXmlParser" title="rawData2(my: var XmlParser): lent string">rawData2(my: var XmlParser): lent string</a></li>
- </ul>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#18" id="68">Templates</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">attrKey
- <li><a class="reference" href="#attrKey.t%2CXmlParser" title="attrKey(my: XmlParser): string">attrKey(my: XmlParser): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">attrValue
- <li><a class="reference" href="#attrValue.t%2CXmlParser" title="attrValue(my: XmlParser): string">attrValue(my: XmlParser): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">charData
- <li><a class="reference" href="#charData.t%2CXmlParser" title="charData(my: XmlParser): string">charData(my: XmlParser): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">elementName
- <li><a class="reference" href="#elementName.t%2CXmlParser" title="elementName(my: XmlParser): string">elementName(my: XmlParser): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">entityName
- <li><a class="reference" href="#entityName.t%2CXmlParser" title="entityName(my: XmlParser): string">entityName(my: XmlParser): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">piName
- <li><a class="reference" href="#piName.t%2CXmlParser" title="piName(my: XmlParser): string">piName(my: XmlParser): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">piRest
- <li><a class="reference" href="#piRest.t%2CXmlParser" title="piRest(my: XmlParser): string">piRest(my: XmlParser): string</a></li>
- </ul>
- </ul>
- </details>
- </li>
- </ul>
- </div>
- <div class="nine columns" id="content">
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L1" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
- <div id="tocRoot"></div>
-
- <p class="module-desc">This module implements a simple high performance <span id="xml_1">XML</span> / <span id="html_1">HTML</span> parser. The only encoding that is supported is UTF-8. The parser has been designed to be somewhat error correcting, so that even most "wild HTML" found on the web can be parsed with it. <strong>Note:</strong> This parser does not check that each <tt class="docutils literal"><span class="pre"><tag></span></tt> has a corresponding <tt class="docutils literal"><span class="pre"></tag></span></tt>! These checks have do be implemented by the client code for various reasons:<ul class="simple"><li>Old HTML contains tags that have no end tag: <tt class="docutils literal"><span class="pre"><br></span></tt> for example.</li>
- <li>HTML tags are case insensitive, XML tags are case sensitive. Since this library can parse both, only the client knows which comparison is to be used.</li>
- <li>Thus the checks would have been very difficult to implement properly with little benefit, especially since they are simple to implement in the client. The client should use the <tt class="docutils literal"><span class="pre"><span class="Identifier">errorMsgExpected</span></span></tt> proc to generate a nice error message that fits the other error messages this library creates.</li>
- </ul>
- <h1><a class="toc-backref" id="example-1colon-retrieve-html-title" href="#example-1colon-retrieve-html-title">Example 1: Retrieve HTML title</a></h1><p>The file <tt class="docutils literal"><span class="pre">examples/htmltitle.nim</span></tt> demonstrates how to use the XML parser to accomplish a simple task: To determine the title of an HTML document.</p>
- <p><pre class="listing"><span class="Comment"># Example program to show the parsexml module</span>
- <span class="Comment"># This program reads an HTML file and writes its title to stdout.</span>
- <span class="Comment"># Errors and whitespace are ignored.</span>
- <span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Punctuation">[</span><span class="Identifier">os</span><span class="Punctuation">,</span> <span class="Identifier">streams</span><span class="Punctuation">,</span> <span class="Identifier">parsexml</span><span class="Punctuation">,</span> <span class="Identifier">strutils</span><span class="Punctuation">]</span>
- <span class="Keyword">if</span> <span class="Identifier">paramCount</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator"><</span> <span class="DecNumber">1</span><span class="Punctuation">:</span>
- <span class="Identifier">quit</span><span class="Punctuation">(</span><span class="StringLit">"Usage: htmltitle filename[.html]"</span><span class="Punctuation">)</span>
- <span class="Keyword">var</span> <span class="Identifier">filename</span> <span class="Operator">=</span> <span class="Identifier">addFileExt</span><span class="Punctuation">(</span><span class="Identifier">paramStr</span><span class="Punctuation">(</span><span class="DecNumber">1</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="StringLit">"html"</span><span class="Punctuation">)</span>
- <span class="Keyword">var</span> <span class="Identifier">s</span> <span class="Operator">=</span> <span class="Identifier">newFileStream</span><span class="Punctuation">(</span><span class="Identifier">filename</span><span class="Punctuation">,</span> <span class="Identifier">fmRead</span><span class="Punctuation">)</span>
- <span class="Keyword">if</span> <span class="Identifier">s</span> <span class="Operator">==</span> <span class="Keyword">nil</span><span class="Punctuation">:</span> <span class="Identifier">quit</span><span class="Punctuation">(</span><span class="StringLit">"cannot open the file "</span> <span class="Operator">&</span> <span class="Identifier">filename</span><span class="Punctuation">)</span>
- <span class="Keyword">var</span> <span class="Identifier">x</span><span class="Punctuation">:</span> <span class="Identifier">XmlParser</span>
- <span class="Identifier">open</span><span class="Punctuation">(</span><span class="Identifier">x</span><span class="Punctuation">,</span> <span class="Identifier">s</span><span class="Punctuation">,</span> <span class="Identifier">filename</span><span class="Punctuation">)</span>
- <span class="Keyword">while</span> <span class="Identifier">true</span><span class="Punctuation">:</span>
- <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">next</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Keyword">case</span> <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">kind</span>
- <span class="Keyword">of</span> <span class="Identifier">xmlElementStart</span><span class="Punctuation">:</span>
- <span class="Keyword">if</span> <span class="Identifier">cmpIgnoreCase</span><span class="Punctuation">(</span><span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">elementName</span><span class="Punctuation">,</span> <span class="StringLit">"title"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span><span class="Punctuation">:</span>
- <span class="Keyword">var</span> <span class="Identifier">title</span> <span class="Operator">=</span> <span class="StringLit">""</span>
- <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">next</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Comment"># skip "<title>"</span>
- <span class="Keyword">while</span> <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">kind</span> <span class="Operator">==</span> <span class="Identifier">xmlCharData</span><span class="Punctuation">:</span>
- <span class="Identifier">title</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">charData</span><span class="Punctuation">)</span>
- <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">next</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Keyword">if</span> <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">kind</span> <span class="Operator">==</span> <span class="Identifier">xmlElementEnd</span> <span class="Keyword">and</span> <span class="Identifier">cmpIgnoreCase</span><span class="Punctuation">(</span><span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">elementName</span><span class="Punctuation">,</span> <span class="StringLit">"title"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span><span class="Punctuation">:</span>
- <span class="Identifier">echo</span><span class="Punctuation">(</span><span class="StringLit">"Title: "</span> <span class="Operator">&</span> <span class="Identifier">title</span><span class="Punctuation">)</span>
- <span class="Identifier">quit</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Comment"># Success!</span>
- <span class="Keyword">else</span><span class="Punctuation">:</span>
- <span class="Identifier">echo</span><span class="Punctuation">(</span><span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">errorMsgExpected</span><span class="Punctuation">(</span><span class="StringLit">"/title"</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
-
- <span class="Keyword">of</span> <span class="Identifier">xmlEof</span><span class="Punctuation">:</span> <span class="Keyword">break</span> <span class="Comment"># end of file reached</span>
- <span class="Keyword">else</span><span class="Punctuation">:</span> <span class="Keyword">discard</span> <span class="Comment"># ignore other events</span>
- <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Identifier">quit</span><span class="Punctuation">(</span><span class="StringLit">"Could not determine title!"</span><span class="Punctuation">)</span></pre></p>
- <h1><a class="toc-backref" id="example-2colon-retrieve-all-html-links" href="#example-2colon-retrieve-all-html-links">Example 2: Retrieve all HTML links</a></h1><p>The file <tt class="docutils literal"><span class="pre">examples/htmlrefs.nim</span></tt> demonstrates how to use the XML parser to accomplish another simple task: To determine all the links an HTML document contains.</p>
- <p><pre class="listing"><span class="Comment"># Example program to show the new parsexml module</span>
- <span class="Comment"># This program reads an HTML file and writes all its used links to stdout.</span>
- <span class="Comment"># Errors and whitespace are ignored.</span>
- <span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Punctuation">[</span><span class="Identifier">os</span><span class="Punctuation">,</span> <span class="Identifier">streams</span><span class="Punctuation">,</span> <span class="Identifier">parsexml</span><span class="Punctuation">,</span> <span class="Identifier">strutils</span><span class="Punctuation">]</span>
- <span class="Keyword">proc</span> <span class="Punctuation">`</span><span class="Operator">=?=</span><span class="Punctuation">`</span> <span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">,</span> <span class="Identifier">b</span><span class="Punctuation">:</span> <span class="Identifier">string</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">bool</span> <span class="Operator">=</span>
- <span class="Comment"># little trick: define our own comparator that ignores case</span>
- <span class="Keyword">return</span> <span class="Identifier">cmpIgnoreCase</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">,</span> <span class="Identifier">b</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Keyword">if</span> <span class="Identifier">paramCount</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator"><</span> <span class="DecNumber">1</span><span class="Punctuation">:</span>
- <span class="Identifier">quit</span><span class="Punctuation">(</span><span class="StringLit">"Usage: htmlrefs filename[.html]"</span><span class="Punctuation">)</span>
- <span class="Keyword">var</span> <span class="Identifier">links</span> <span class="Operator">=</span> <span class="DecNumber">0</span> <span class="Comment"># count the number of links</span>
- <span class="Keyword">var</span> <span class="Identifier">filename</span> <span class="Operator">=</span> <span class="Identifier">addFileExt</span><span class="Punctuation">(</span><span class="Identifier">paramStr</span><span class="Punctuation">(</span><span class="DecNumber">1</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="StringLit">"html"</span><span class="Punctuation">)</span>
- <span class="Keyword">var</span> <span class="Identifier">s</span> <span class="Operator">=</span> <span class="Identifier">newFileStream</span><span class="Punctuation">(</span><span class="Identifier">filename</span><span class="Punctuation">,</span> <span class="Identifier">fmRead</span><span class="Punctuation">)</span>
- <span class="Keyword">if</span> <span class="Identifier">s</span> <span class="Operator">==</span> <span class="Keyword">nil</span><span class="Punctuation">:</span> <span class="Identifier">quit</span><span class="Punctuation">(</span><span class="StringLit">"cannot open the file "</span> <span class="Operator">&</span> <span class="Identifier">filename</span><span class="Punctuation">)</span>
- <span class="Keyword">var</span> <span class="Identifier">x</span><span class="Punctuation">:</span> <span class="Identifier">XmlParser</span>
- <span class="Identifier">open</span><span class="Punctuation">(</span><span class="Identifier">x</span><span class="Punctuation">,</span> <span class="Identifier">s</span><span class="Punctuation">,</span> <span class="Identifier">filename</span><span class="Punctuation">)</span>
- <span class="Identifier">next</span><span class="Punctuation">(</span><span class="Identifier">x</span><span class="Punctuation">)</span> <span class="Comment"># get first event</span>
- <span class="Keyword">block</span> <span class="Identifier">mainLoop</span><span class="Punctuation">:</span>
- <span class="Keyword">while</span> <span class="Identifier">true</span><span class="Punctuation">:</span>
- <span class="Keyword">case</span> <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">kind</span>
- <span class="Keyword">of</span> <span class="Identifier">xmlElementOpen</span><span class="Punctuation">:</span>
- <span class="Comment"># the <a href = "xyz"> tag we are interested in always has an attribute,</span>
- <span class="Comment"># thus we search for ``xmlElementOpen`` and not for ``xmlElementStart``</span>
- <span class="Keyword">if</span> <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">elementName</span> <span class="Operator">=?=</span> <span class="StringLit">"a"</span><span class="Punctuation">:</span>
- <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">next</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Keyword">if</span> <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">kind</span> <span class="Operator">==</span> <span class="Identifier">xmlAttribute</span><span class="Punctuation">:</span>
- <span class="Keyword">if</span> <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">attrKey</span> <span class="Operator">=?=</span> <span class="StringLit">"href"</span><span class="Punctuation">:</span>
- <span class="Keyword">var</span> <span class="Identifier">link</span> <span class="Operator">=</span> <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">attrValue</span>
- <span class="Identifier">inc</span><span class="Punctuation">(</span><span class="Identifier">links</span><span class="Punctuation">)</span>
- <span class="Comment"># skip until we have an ``xmlElementClose`` event</span>
- <span class="Keyword">while</span> <span class="Identifier">true</span><span class="Punctuation">:</span>
- <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">next</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Keyword">case</span> <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">kind</span>
- <span class="Keyword">of</span> <span class="Identifier">xmlEof</span><span class="Punctuation">:</span> <span class="Keyword">break</span> <span class="Identifier">mainLoop</span>
- <span class="Keyword">of</span> <span class="Identifier">xmlElementClose</span><span class="Punctuation">:</span> <span class="Keyword">break</span>
- <span class="Keyword">else</span><span class="Punctuation">:</span> <span class="Keyword">discard</span>
- <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">next</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Comment"># skip ``xmlElementClose``</span>
- <span class="Comment"># now we have the description for the ``a`` element</span>
- <span class="Keyword">var</span> <span class="Identifier">desc</span> <span class="Operator">=</span> <span class="StringLit">""</span>
- <span class="Keyword">while</span> <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">kind</span> <span class="Operator">==</span> <span class="Identifier">xmlCharData</span><span class="Punctuation">:</span>
- <span class="Identifier">desc</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">charData</span><span class="Punctuation">)</span>
- <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">next</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Identifier">echo</span><span class="Punctuation">(</span><span class="Identifier">desc</span> <span class="Operator">&</span> <span class="StringLit">": "</span> <span class="Operator">&</span> <span class="Identifier">link</span><span class="Punctuation">)</span>
- <span class="Keyword">else</span><span class="Punctuation">:</span>
- <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">next</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Keyword">of</span> <span class="Identifier">xmlEof</span><span class="Punctuation">:</span> <span class="Keyword">break</span> <span class="Comment"># end of file reached</span>
- <span class="Keyword">of</span> <span class="Identifier">xmlError</span><span class="Punctuation">:</span>
- <span class="Identifier">echo</span><span class="Punctuation">(</span><span class="Identifier">errorMsg</span><span class="Punctuation">(</span><span class="Identifier">x</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
- <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">next</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Keyword">else</span><span class="Punctuation">:</span> <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">next</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Comment"># skip other events</span>
- <span class="Identifier">echo</span><span class="Punctuation">(</span><span class="Operator">$</span><span class="Identifier">links</span> <span class="Operator">&</span> <span class="StringLit">" link(s) found!"</span><span class="Punctuation">)</span>
- <span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
- </p>
- <div class="section" id="6">
- <h1><a class="toc-backref" href="#6">Imports</a></h1>
- <dl class="item">
- <a class="reference external" href="strutils.html">strutils</a>, <a class="reference external" href="lexbase.html">lexbase</a>, <a class="reference external" href="streams.html">streams</a>, <a class="reference external" href="unicode.html">unicode</a>, <a class="reference external" href="assertions.html">assertions</a>, <a class="reference external" href="syncio.html">syncio</a>, <a class="reference external" href="os.html">os</a>
- </dl>
- </div>
- <div class="section" id="7">
- <h1><a class="toc-backref" href="#7">Types</a></h1>
- <dl class="item">
- <div id="XmlErrorKind">
- <dt><pre><a href="parsexml.html#XmlErrorKind"><span class="Identifier">XmlErrorKind</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
- <span class="Identifier">errNone</span><span class="Other">,</span> <span class="Comment">## no error</span>
- <span class="Identifier">errEndOfCDataExpected</span><span class="Other">,</span> <span class="Comment">## ``]]>`` expected</span>
- <span class="Identifier">errNameExpected</span><span class="Other">,</span> <span class="Comment">## name expected</span>
- <span class="Identifier">errSemicolonExpected</span><span class="Other">,</span> <span class="Comment">## ``;`` expected</span>
- <span class="Identifier">errQmGtExpected</span><span class="Other">,</span> <span class="Comment">## ``?>`` expected</span>
- <span class="Identifier">errGtExpected</span><span class="Other">,</span> <span class="Comment">## ``>`` expected</span>
- <span class="Identifier">errEqExpected</span><span class="Other">,</span> <span class="Comment">## ``=`` expected</span>
- <span class="Identifier">errQuoteExpected</span><span class="Other">,</span> <span class="Comment">## ``"`` or ``'`` expected</span>
- <span class="Identifier">errEndOfCommentExpected</span><span class="Other">,</span> <span class="Comment">## ``-->`` expected</span>
- <span class="Identifier">errAttributeValueExpected</span> <span class="Comment">## non-empty attribute value expected</span></pre></dt>
- <dd>
-
- enumeration that lists all errors that can occur
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L176" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L176" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="XmlEventKind">
- <dt><pre><a href="parsexml.html#XmlEventKind"><span class="Identifier">XmlEventKind</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
- <span class="Identifier">xmlError</span><span class="Other">,</span> <span class="Comment">## an error occurred during parsing</span>
- <span class="Identifier">xmlEof</span><span class="Other">,</span> <span class="Comment">## end of file reached</span>
- <span class="Identifier">xmlCharData</span><span class="Other">,</span> <span class="Comment">## character data</span>
- <span class="Identifier">xmlWhitespace</span><span class="Other">,</span> <span class="Comment">## whitespace has been parsed</span>
- <span class="Identifier">xmlComment</span><span class="Other">,</span> <span class="Comment">## a comment has been parsed</span>
- <span class="Identifier">xmlPI</span><span class="Other">,</span> <span class="Comment">## processing instruction (``<?name something ?>``)</span>
- <span class="Identifier">xmlElementStart</span><span class="Other">,</span> <span class="Comment">## ``<elem>``</span>
- <span class="Identifier">xmlElementEnd</span><span class="Other">,</span> <span class="Comment">## ``</elem>``</span>
- <span class="Identifier">xmlElementOpen</span><span class="Other">,</span> <span class="Comment">## ``<elem</span>
- <span class="Identifier">xmlAttribute</span><span class="Other">,</span> <span class="Comment">## ``key = "value"`` pair</span>
- <span class="Identifier">xmlElementClose</span><span class="Other">,</span> <span class="Comment">## ``>``</span>
- <span class="Identifier">xmlCData</span><span class="Other">,</span> <span class="Comment">## ``<![CDATA[`` ... data ... ``]]>``</span>
- <span class="Identifier">xmlEntity</span><span class="Other">,</span> <span class="Comment">## &entity;</span>
- <span class="Identifier">xmlSpecial</span> <span class="Comment">## ``<! ... data ... >``</span></pre></dt>
- <dd>
-
- enumeration of all events that may occur when parsing
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L160" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L160" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="XmlParseOption">
- <dt><pre><a href="parsexml.html#XmlParseOption"><span class="Identifier">XmlParseOption</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
- <span class="Identifier">reportWhitespace</span><span class="Other">,</span> <span class="Comment">## report whitespace</span>
- <span class="Identifier">reportComments</span><span class="Other">,</span> <span class="Comment">## report comments</span>
- <span class="Identifier">allowUnquotedAttribs</span><span class="Other">,</span> <span class="Comment">## allow unquoted attribute values (for HTML)</span>
- <span class="Identifier">allowEmptyAttribs</span> <span class="Comment">## allow empty attributes (without explicit value)</span></pre></dt>
- <dd>
-
- options for the XML parser
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L191" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L191" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="XmlParser">
- <dt><pre><a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a> <span class="Other">=</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="lexbase.html#BaseLexer"><span class="Identifier">BaseLexer</span></a></pre></dt>
- <dd>
-
- the parser object.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L197" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L197" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </dl>
- </div>
- <div class="section" id="12">
- <h1><a class="toc-backref" href="#12">Procs</a></h1>
- <dl class="item">
- <div id="close-procs-all">
- <div id="close,XmlParser">
- <dt><pre><span class="Keyword">proc</span> <a href="#close%2CXmlParser"><span class="Identifier">close</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">)</span> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">WriteIOEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- closes the parser <tt class="docutils literal"><span class="pre"><span class="Identifier">my</span></span></tt> and its associated input stream.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L238" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L238" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="errorMsg-procs-all">
- <div id="errorMsg,XmlParser">
- <dt><pre><span class="Keyword">proc</span> <a href="#errorMsg%2CXmlParser"><span class="Identifier">errorMsg</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- returns a helpful error message for the event <tt class="docutils literal"><span class="pre">xmlError</span></tt>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L327" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L327" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="errorMsg,XmlParser,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#errorMsg%2CXmlParser%2Cstring"><span class="Identifier">errorMsg</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">;</span> <span class="Identifier">msg</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- returns an error message with text <tt class="docutils literal"><span class="pre"><span class="Identifier">msg</span></span></tt> in the same format as the other error messages
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L339" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L339" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="errorMsgExpected-procs-all">
- <div id="errorMsgExpected,XmlParser,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#errorMsgExpected%2CXmlParser%2Cstring"><span class="Identifier">errorMsgExpected</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">;</span> <span class="Identifier">tag</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- returns an error message "<tag> expected" in the same format as the other error messages
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L333" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L333" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getColumn-procs-all">
- <div id="getColumn,XmlParser">
- <dt><pre><span class="Keyword">proc</span> <a href="#getColumn%2CXmlParser"><span class="Identifier">getColumn</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- get the current column the parser has arrived at.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L315" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L315" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getFilename-procs-all">
- <div id="getFilename,XmlParser">
- <dt><pre><span class="Keyword">proc</span> <a href="#getFilename%2CXmlParser"><span class="Identifier">getFilename</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- get the filename of the file that the parser processes.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L323" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L323" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getLine-procs-all">
- <div id="getLine,XmlParser">
- <dt><pre><span class="Keyword">proc</span> <a href="#getLine%2CXmlParser"><span class="Identifier">getLine</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- get the current line the parser has arrived at.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L319" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L319" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="kind-procs-all">
- <div id="kind,XmlParser">
- <dt><pre><span class="Keyword">proc</span> <a href="#kind%2CXmlParser"><span class="Identifier">kind</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="parsexml.html#XmlEventKind"><span class="Identifier">XmlEventKind</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- returns the current event type for the XML parser
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L242" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L242" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="next-procs-all">
- <div id="next,XmlParser">
- <dt><pre><span class="Keyword">proc</span> <a href="#next%2CXmlParser"><span class="Identifier">next</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadIOEffect</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- retrieves the first/next event. This controls the parser.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L757" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L757" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="open-procs-all">
- <div id="open,XmlParser,Stream,string,set[XmlParseOption]">
- <dt><pre><span class="Keyword">proc</span> <a href="#open%2CXmlParser%2CStream%2Cstring%2Cset%5BXmlParseOption%5D"><span class="Identifier">open</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">;</span> <span class="Identifier">input</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">;</span> <span class="Identifier">filename</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span>
- <span class="Identifier">options</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="parsexml.html#XmlParseOption"><span class="Identifier">XmlParseOption</span></a><span class="Other">]</span> <span class="Other">=</span> <span class="Other">{</span><span class="Other">}</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadIOEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- initializes the parser with an input stream. <tt class="docutils literal"><span class="pre"><span class="Identifier">Filename</span></span></tt> is only used for nice error messages. The parser's behaviour can be controlled by the <tt class="docutils literal"><span class="pre"><span class="Identifier">options</span></span></tt> parameter: If <tt class="docutils literal"><span class="pre"><span class="Identifier">options</span></span></tt> contains <tt class="docutils literal"><span class="pre">reportWhitespace</span></tt> a whitespace token is reported as an <tt class="docutils literal"><span class="pre">xmlWhitespace</span></tt> event. If <tt class="docutils literal"><span class="pre"><span class="Identifier">options</span></span></tt> contains <tt class="docutils literal"><span class="pre">reportComments</span></tt> a comment token is reported as an <tt class="docutils literal"><span class="pre">xmlComment</span></tt> event.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L220" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L220" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="rawData-procs-all">
- <div id="rawData,XmlParser">
- <dt><pre><span class="Keyword">proc</span> <a href="#rawData%2CXmlParser"><span class="Identifier">rawData</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#lent"><span class="Identifier">lent</span></a> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- returns the underlying 'data' string by reference. This is only used for speed hacks.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L305" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L305" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="rawData2-procs-all">
- <div id="rawData2,XmlParser">
- <dt><pre><span class="Keyword">proc</span> <a href="#rawData2%2CXmlParser"><span class="Identifier">rawData2</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#lent"><span class="Identifier">lent</span></a> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- returns the underlying second 'data' string by reference. This is only used for speed hacks.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L310" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L310" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- </dl>
- </div>
- <div class="section" id="18">
- <h1><a class="toc-backref" href="#18">Templates</a></h1>
- <dl class="item">
- <div id="attrKey-templates-all">
- <div id="attrKey.t,XmlParser">
- <dt><pre><span class="Keyword">template</span> <a href="#attrKey.t%2CXmlParser"><span class="Identifier">attrKey</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
- <dd>
-
- returns the attribute key for the event <tt class="docutils literal"><span class="pre">xmlAttribute</span></tt> Raises an assertion in debug mode if <tt class="docutils literal"><span class="pre">my.kind</span></tt> is not <tt class="docutils literal"><span class="pre">xmlAttribute</span></tt>. In release mode, this will not trigger an error but the value returned will not be valid.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L273" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L273" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="attrValue-templates-all">
- <div id="attrValue.t,XmlParser">
- <dt><pre><span class="Keyword">template</span> <a href="#attrValue.t%2CXmlParser"><span class="Identifier">attrValue</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
- <dd>
-
- returns the attribute value for the event <tt class="docutils literal"><span class="pre">xmlAttribute</span></tt> Raises an assertion in debug mode if <tt class="docutils literal"><span class="pre">my.kind</span></tt> is not <tt class="docutils literal"><span class="pre">xmlAttribute</span></tt>. In release mode, this will not trigger an error but the value returned will not be valid.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L281" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L281" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="charData-templates-all">
- <div id="charData.t,XmlParser">
- <dt><pre><span class="Keyword">template</span> <a href="#charData.t%2CXmlParser"><span class="Identifier">charData</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
- <dd>
-
- returns the character data for the events: <tt class="docutils literal"><span class="pre">xmlCharData</span></tt>, <tt class="docutils literal"><span class="pre">xmlWhitespace</span></tt>, <tt class="docutils literal"><span class="pre">xmlComment</span></tt>, <tt class="docutils literal"><span class="pre">xmlCData</span></tt>, <tt class="docutils literal"><span class="pre">xmlSpecial</span></tt> Raises an assertion in debug mode if <tt class="docutils literal"><span class="pre">my.kind</span></tt> is not one of those events. In release mode, this will not trigger an error but the value returned will not be valid.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L246" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L246" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="elementName-templates-all">
- <div id="elementName.t,XmlParser">
- <dt><pre><span class="Keyword">template</span> <a href="#elementName.t%2CXmlParser"><span class="Identifier">elementName</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
- <dd>
-
- returns the element name for the events: <tt class="docutils literal"><span class="pre">xmlElementStart</span></tt>, <tt class="docutils literal"><span class="pre">xmlElementEnd</span></tt>, <tt class="docutils literal"><span class="pre">xmlElementOpen</span></tt> Raises an assertion in debug mode if <tt class="docutils literal"><span class="pre">my.kind</span></tt> is not one of those events. In release mode, this will not trigger an error but the value returned will not be valid.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L256" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L256" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="entityName-templates-all">
- <div id="entityName.t,XmlParser">
- <dt><pre><span class="Keyword">template</span> <a href="#entityName.t%2CXmlParser"><span class="Identifier">entityName</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
- <dd>
-
- returns the entity name for the event: <tt class="docutils literal"><span class="pre">xmlEntity</span></tt> Raises an assertion in debug mode if <tt class="docutils literal"><span class="pre">my.kind</span></tt> is not <tt class="docutils literal"><span class="pre">xmlEntity</span></tt>. In release mode, this will not trigger an error but the value returned will not be valid.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L265" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L265" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="piName-templates-all">
- <div id="piName.t,XmlParser">
- <dt><pre><span class="Keyword">template</span> <a href="#piName.t%2CXmlParser"><span class="Identifier">piName</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
- <dd>
-
- returns the processing instruction name for the event <tt class="docutils literal"><span class="pre">xmlPI</span></tt> Raises an assertion in debug mode if <tt class="docutils literal"><span class="pre">my.kind</span></tt> is not <tt class="docutils literal"><span class="pre">xmlPI</span></tt>. In release mode, this will not trigger an error but the value returned will not be valid.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L289" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L289" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="piRest-templates-all">
- <div id="piRest.t,XmlParser">
- <dt><pre><span class="Keyword">template</span> <a href="#piRest.t%2CXmlParser"><span class="Identifier">piRest</span></a><span class="Other">(</span><span class="Identifier">my</span><span class="Other">:</span> <a href="parsexml.html#XmlParser"><span class="Identifier">XmlParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
- <dd>
-
- returns the rest of the processing instruction for the event <tt class="docutils literal"><span class="pre">xmlPI</span></tt> Raises an assertion in debug mode if <tt class="docutils literal"><span class="pre">my.kind</span></tt> is not <tt class="docutils literal"><span class="pre">xmlPI</span></tt>. In release mode, this will not trigger an error but the value returned will not be valid.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsexml.nim#L297" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsexml.nim#L297" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- </dl>
- </div>
- </div>
- </div>
- <div class="twelve-columns footer">
- <span class="nim-sprite"></span>
- <br>
- <small style="color: var(--hint);">Made with Nim. Generated: 2025-02-06 22:28:02 UTC</small>
- </div>
- </div>
- </div>
- <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
-
- </body>
- </html>
|