public override object Create(object parent, object configContext, XmlNode section) { var processor = new XmlProcessor(); var result = processor.Process(section); return(base.Create(parent, configContext, result)); }
public void Test_Embedded2() { var resource = Xml.Embedded("hasResourceIncludes.xml"); var interpreter = new XmlInterpreter(resource); var kernel = new DefaultKernel(); var resourceSubSystem = kernel.GetSubSystem(SubSystemConstants.ResourceKey) as IResourceSubSystem; var processor = new XmlProcessor(null, resourceSubSystem); var element = processor.Process(resource); }
public void InvalidFiles() { var files = Directory.GetFiles(GetFullPath(), "Invalid*.xml"); Assert.IsNotEmpty(files); foreach (var fileName in files) { var doc = GetXmlDocument(fileName); var processor = new XmlProcessor(); Assert.Throws(typeof(ConfigurationProcessingException), () => processor.Process(doc.DocumentElement)); } }
public void RunTests() { var files = Directory.GetFiles(GetFullPath(), "*Test.xml"); Assert.IsNotEmpty(files); foreach (var fileName in files) { if (fileName.EndsWith("PropertiesWithAttributesTest.xml")) { continue; } var doc = GetXmlDocument(fileName); var resultFileName = fileName.Substring(0, fileName.Length - 4) + "Result.xml"; var resultDoc = GetXmlDocument(resultFileName); var processor = new XmlProcessor(); try { var result = processor.Process(doc.DocumentElement); var resultDocStr = StripSpaces(resultDoc.OuterXml); var resultStr = StripSpaces(result.OuterXml); // Debug.WriteLine(resultDocStr); // Debug.WriteLine(resultStr); Assert.AreEqual(resultDocStr, resultStr); } catch (Exception e) { throw new Exception("Error processing " + fileName, e); } } }
public void Test_Embedded4() { var resource = Xml.Embedded("hasResourceIncludes.xml"); var interpreter = new XmlInterpreter(resource); var kernel = new DefaultKernel(); var resourceSubSystem = kernel.GetSubSystem(SubSystemConstants.ResourceKey) as IResourceSubSystem; var processor = new XmlProcessor(null, resourceSubSystem); var assemRes = resource as AssemblyResource; Assert.IsNotNull(assemRes); var doc = new XmlDocument(); using (var stream = resource.GetStreamReader()) { doc.Load(stream); } var engine = new DefaultXmlProcessorEngine(null, resourceSubSystem); engine.PushResource(resource); Assert.AreEqual(doc.DocumentElement.InnerText, ""); var element = processor.Process(doc.DocumentElement); engine.PopResource(); }
public override Stream Parse() { VirtualStream elmementStream = new VirtualStream(); XmlWriter elementWriter = XmlWriter.Create(elmementStream, new XmlWriterSettings { ConformanceLevel = ConformanceLevel.Fragment }); XmlSchemaObject.XmlNode schemaNode = new XmlSchemaObject.XmlNode(); XmlProcessor processor = new XmlProcessor(); schemaNode = processor.Process(Settings.Schema, Settings.RootName); if (schemaNode == null) { throw new NullReferenceException($"SchemaNode with name {Settings.RootName} could not be found"); } wtr.WriteStartElement(Settings.Prefix, Settings.RootName, schemaNode.Namespace); string elementName = String.Empty; while (reader.Read()) { switch (reader.TokenType) { case JsonToken.StartObject: XmlSchemaObject.XmlNode objectNode = schemaNode.FirstOrDefaultChild(elementName); var objectStream = WriteObject(objectNode); WriteElementFragment(elementWriter, objectStream); break; case JsonToken.EndObject: if (reader.Depth > 0) { } break; case JsonToken.Date: case JsonToken.String: case JsonToken.Integer: case JsonToken.Float: case JsonToken.Boolean: case JsonToken.Bytes: //All attributes must be written before child elements WriteElementOrAttribute(schemaNode, elementName, wtr, elementWriter); break; case JsonToken.Null: // empty element. do nothing break; case JsonToken.PropertyName: elementName = (string)reader.Value; break; case JsonToken.StartArray: XmlSchemaObject.XmlNode arrayNode = schemaNode.FirstOrDefaultChild(elementName); var arrayStream = WriteArray(arrayNode); WriteElementFragment(elementWriter, arrayStream); break; } } WriteElementFragment(wtr, elmementStream, elementWriter); wtr.WriteEndDocument(); wtr.Flush(); wtr.Close(); m_stm.Position = 0; return(m_stm); }