diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2015-11-08 13:07:38 +0000 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@googlemail.com> | 2015-11-08 13:07:38 +0000 |
commit | 60e5a2b2f53c0bfaa57a48f53b0b3dfcca1bef76 (patch) | |
tree | 35f424bee27be5ce751fb28fa10224dfa8db1479 /lib | |
parent | d8738f8f5dc2d14a04fe09513dc36bc62ffe7357 (diff) | |
parent | 8671656e6f6d8cca67054a925dfdcb8246a97bef (diff) | |
download | Nim-60e5a2b2f53c0bfaa57a48f53b0b3dfcca1bef76.tar.gz |
Merge pull request #3504 from Matt14916/xmlparser-entities
Create entity nodes with xmlparser, add a test to xmlparser
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/xmlparser.nim | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/lib/pure/xmlparser.nim b/lib/pure/xmlparser.nim index 56b122000..2a2c3e1dd 100644 --- a/lib/pure/xmlparser.nim +++ b/lib/pure/xmlparser.nim @@ -96,7 +96,7 @@ proc parse(x: var XmlParser, errors: var seq[string]): XmlNode = next(x) of xmlEntity: ## &entity; - errors.add(errorMsg(x, "unknown entity: " & x.entityName)) + result = newEntity(x.entityName) next(x) of xmlEof: discard @@ -143,17 +143,24 @@ proc loadXml*(path: string): XmlNode = result = loadXml(path, errors) if errors.len > 0: raiseInvalidXml(errors) -when not defined(testing) and isMainModule: - import os +when isMainModule: + when not defined(testing): + import os - var errors: seq[string] = @[] - var x = loadXml(paramStr(1), errors) - for e in items(errors): echo e + var errors: seq[string] = @[] + var x = loadXml(paramStr(1), errors) + for e in items(errors): echo e - var f: File - if open(f, "xmltest.txt", fmWrite): - f.write($x) - f.close() + var f: File + if open(f, "xmltest.txt", fmWrite): + f.write($x) + f.close() + else: + quit("cannot write test.txt") else: - quit("cannot write test.txt") + block: # correctly parse ../../tests/testdata/doc1.xml + let filePath = "tests/testdata/doc1.xml" + var errors: seq[string] = @[] + var xml = loadXml(filePath, errors) + assert(errors.len == 0, "The file tests/testdata/doc1.xml should be parsed without errors.") |