From 52140d52210eda0f25ecab9f89b5c73473e9d8e0 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 17 Apr 2016 18:57:29 +0100 Subject: Add CLI for .NET version --- .../mammoth/internal/xml/parsing/SimpleSax.cs | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'dotnet/Mammoth/Couscous/mammoth/internal/xml') diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/xml/parsing/SimpleSax.cs b/dotnet/Mammoth/Couscous/mammoth/internal/xml/parsing/SimpleSax.cs index 8ebdf28..65f63c3 100644 --- a/dotnet/Mammoth/Couscous/mammoth/internal/xml/parsing/SimpleSax.cs +++ b/dotnet/Mammoth/Couscous/mammoth/internal/xml/parsing/SimpleSax.cs @@ -1,9 +1,38 @@ using Mammoth.Couscous.java.io; +using Mammoth.Couscous.java.util; +using System.Xml; namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.xml.parsing { internal static class SimpleSax { internal static void parseStream(InputStream input, SimpleSaxHandler handler) { - throw new System.NotImplementedException(); + var reader = XmlReader.Create(input.Stream); + while (reader.Read()) { + switch (reader.NodeType) { + case XmlNodeType.Element: + var name = new ElementName(reader.NamespaceURI, reader.LocalName); + var attributes = new HashMap(); + var isEmpty = reader.IsEmptyElement; + for (int attributeIndex = 0; attributeIndex < reader.AttributeCount; attributeIndex++) { + reader.MoveToAttribute(attributeIndex); + attributes.put(new ElementName(reader.NamespaceURI, reader.LocalName), reader.Value); + } + handler.startElement(name, attributes); + if (isEmpty) { + handler.endElement(); + } + break; + case XmlNodeType.CDATA: + case XmlNodeType.Text: + case XmlNodeType.SignificantWhitespace: + handler.characters(reader.Value); + break; + case XmlNodeType.EntityReference: + throw new System.NotImplementedException(); + case XmlNodeType.EndElement: + handler.endElement(); + break; + } + } } internal static void parseString(string value, SimpleSaxHandler handler) { -- cgit v1.2.3