protected void HandlePostProcessingTag(IPostProcessReader pullParserReader) { if (!pullParserReader.IsStartTag()) { return; } String elementName = pullParserReader.GetElementName(); if (!XmlDictionary.PostProcessElement.Equals(elementName)) { throw new Exception("Only <" + XmlDictionary.PostProcessElement + "> allowed as second child of root. <" + elementName + "> found."); } pullParserReader.NextTag(); IXmlPostProcessorRegistry xmlPostProcessorRegistry = XmlPostProcessorRegistry; while (pullParserReader.IsStartTag()) { elementName = pullParserReader.GetElementName(); IXmlPostProcessor xmlPostProcessor = xmlPostProcessorRegistry.GetXmlPostProcessor(elementName); if (xmlPostProcessor == null) { throw new Exception("Post processing tag <" + elementName + "> not supported."); } xmlPostProcessor.ProcessRead(pullParserReader); pullParserReader.MoveOverElementEnd(); } }
protected void PostProcess(IPostProcessWriter writer) { ILinkedMap <String, IXmlPostProcessor> xmlPostProcessors = XmlPostProcessorRegistry.GetXmlPostProcessors(); ILinkedMap <String, Object> ppResults = new LinkedHashMap <String, Object>((int)(xmlPostProcessors.Count / 0.75 + 1)); foreach (Entry <String, IXmlPostProcessor> entry in xmlPostProcessors) { String tagName = entry.Key; IXmlPostProcessor xmlPostProcessor = entry.Value; Object result = xmlPostProcessor.ProcessWrite(writer); if (result != null) { ppResults.Put(tagName, result); } } if (ppResults.Count == 0) { return; } String postProcessElement = XmlDictionary.PostProcessElement; writer.WriteStartElement(postProcessElement); foreach (Entry <String, Object> entry in ppResults) { String tagName = entry.Key; Object result = entry.Value; writer.WriteOpenElement(tagName); writer.WriteObject(result); writer.WriteCloseElement(tagName); } writer.WriteCloseElement(postProcessElement); }