From 097c508897ccb53137916c431836689ba0fc0186 Mon Sep 17 00:00:00 2001 From: Matt Sullivan Date: Fri, 30 Oct 2015 23:42:29 -0500 Subject: [PATCH 1/2] Create entity nodes with xmlparser --- lib/pure/xmlparser.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pure/xmlparser.nim b/lib/pure/xmlparser.nim index 56b1220008..b1c6acacef 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 From 8671656e6f6d8cca67054a925dfdcb8246a97bef Mon Sep 17 00:00:00 2001 From: Matt Sullivan Date: Sat, 31 Oct 2015 13:30:07 -0500 Subject: [PATCH 2/2] Add a test to xmlparser --- lib/pure/xmlparser.nim | 27 +++++++++++++++++---------- tests/testdata/doc1.xml | 1 + 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/pure/xmlparser.nim b/lib/pure/xmlparser.nim index b1c6acacef..2a2c3e1dd8 100644 --- a/lib/pure/xmlparser.nim +++ b/lib/pure/xmlparser.nim @@ -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.") diff --git a/tests/testdata/doc1.xml b/tests/testdata/doc1.xml index 4e77481aa1..07cbceeb73 100644 --- a/tests/testdata/doc1.xml +++ b/tests/testdata/doc1.xml @@ -5,6 +5,7 @@ bla ah absy hsh hsh + &woohoo; sjj bla