diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-04-17 18:57:29 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-04-17 18:58:12 +0100 |
| commit | 52140d52210eda0f25ecab9f89b5c73473e9d8e0 (patch) | |
| tree | cb383edb71e44b8ae7b2b0d0890f13574d1922f0 /dotnet/Mammoth/Couscous/mammoth/internal/xml | |
| parent | 0f9ef005f063198ea2e16ca36beaead4bd5e3824 (diff) | |
Add CLI for .NET version
Diffstat (limited to 'dotnet/Mammoth/Couscous/mammoth/internal/xml')
| -rw-r--r-- | dotnet/Mammoth/Couscous/mammoth/internal/xml/parsing/SimpleSax.cs | 31 |
1 files changed, 30 insertions, 1 deletions
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<ElementName, string>(); + 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) { |
