예제 #1
0
 public void Process(XmlWriter output, FormHandlerInput inputData)
 {
     InternalFormContext fc = new InternalFormContext(inputData, output, this);
     fc.FirstElementHandled = false;
     Process(fc);
 }
예제 #2
0
 /// <summary>
 /// Odczytuje element z XML-a i zwraca go jako elementInfo. Pozycja w node siê nie zmienia
 /// </summary>
 /// <param name="node"></param>
 /// <param name="ctx"></param>
 /// <returns></returns>
 private ElementInfo GetElementInfo(XPathNavigator node, InternalFormContext ctx)
 {
     Debug.Assert(node.NodeType == XPathNodeType.Element);
     ElementInfo ei = new ElementInfo(node.Prefix, node.LocalName, node.NamespaceURI, node.IsEmptyElement, ctx.ElementStack.Count);
     if (node.MoveToFirstAttribute())
     {
         do
         {
             AttributeInfo ai = new AttributeInfo();
             ai.Prefix = node.Prefix;
             ai.Name = node.LocalName;
             ai.NamespaceUri = node.NamespaceURI;
             ai.Value = node.Value;
             ei.Attributes.Add(ai.Name, ai);
         }
         while (node.MoveToNextAttribute());
         node.MoveToParent();
     }
     return ei;
 }
예제 #3
0
 private void VisitNode(XPathNavigator node, InternalFormContext ctx)
 {
     if (node.NodeType == XPathNodeType.Root)
     {
         log.Debug("Root node");
         ctx.Output.WriteStartDocument();
         VisitChildren(node, ctx);
         log.Debug("Root node end");
     }
     else if (node.NodeType == XPathNodeType.Element)
     {
         ProcessElementNode(node, ctx);
     }
     else if (node.NodeType == XPathNodeType.Comment)
     {
         log.Debug("Comment node: {0}", node.Value);
         ctx.Output.WriteComment(node.Value);
     }
     else if (node.NodeType == XPathNodeType.ProcessingInstruction)
     {
         log.Debug("Processing instruction: {0}:{1}", node.Name, node.Value);
         ctx.Output.WriteProcessingInstruction(node.Name, node.Value);
     }
     else if (node.NodeType == XPathNodeType.Attribute)
     {
         throw new Exception("Attribute not expected here");
     }
     else if (node.NodeType == XPathNodeType.Namespace)
     {
         log.Debug("Namespace: {0}", node.Value);
         throw new Exception("Namespace not expected");
     }
     else if (node.NodeType == XPathNodeType.Text)
     {
         ctx.Output.WriteString(node.Value);
     }
     else if (node.NodeType == XPathNodeType.SignificantWhitespace ||
             node.NodeType == XPathNodeType.Whitespace)
     {
         ctx.Output.WriteWhitespace(node.Value);
     }
     else
     {
         throw new Exception("Unexpected node type: " + node.NodeType);
     }
 }
예제 #4
0
 private void VisitChildren(XPathNavigator node, InternalFormContext ctx)
 {
     if (node.MoveToFirstChild())
     {
         do
         {
             VisitNode(node, ctx);
         } while (node.MoveToNext());
         node.MoveToParent();
     }
 }
예제 #5
0
        private void ProcessElementNode(XPathNavigator node, InternalFormContext ctx)
        {
            Debug.Assert(node.NodeType == XPathNodeType.Element);
            log.Debug("Processing element node: {0} ({1})", node.Name, node.NamespaceURI);
            if (IsPreprocessElement(node))
            {
                PreprocessElementNode(node, ctx);
            }
            else
            {
                ctx.Output.WriteStartElement(node.Prefix, node.LocalName, node.NamespaceURI);
                if (node.MoveToFirstAttribute())
                {
                    do
                    {
                        ctx.Output.WriteAttributeString(node.Prefix, node.LocalName, node.NamespaceURI, node.Value);
                    } while (node.MoveToNextAttribute());
                    node.MoveToParent();
                }

                if (!ctx.FirstElementHandled)
                {
                    if (node.MoveToFirstNamespace())
                    {
                        do
                        {
                            log.Debug("Writing namespace declaration: {0}:{1}", node.LocalName, node.Value);
                            ctx.Output.WriteAttributeString("xmlns", node.LocalName, null, node.Value);
                        }
                        while (node.MoveToNextNamespace());
                        node.MoveToParent();
                    }
                    ctx.FirstElementHandled = true;
                }

                if (!node.IsEmptyElement)
                {
                    VisitChildren(node, ctx);
                }
                ctx.Output.WriteEndElement();
                log.Debug("End processing element node: {0} ({1})", node.Name, node.NamespaceURI);
            }
        }
예제 #6
0
 private void Process(InternalFormContext ctx)
 {
     XPathNavigator nav = GetDocumentNavigator();
     VisitNode(nav, ctx);
 }
예제 #7
0
        private void PreprocessElementNode(XPathNavigator node, InternalFormContext ctx)
        {
            log.Debug("Preprocessing node {0}", node.Name);
            ElementInfo ei = GetElementInfo(node, ctx);
            IElementHandler handler = GetHandler(ei);
            ei.Handler = handler;
            ctx.ElementStack.Insert(ctx.ElementStack.Count, ei);
            ctx.SkipElementContent = false;
            handler.ElementStart(ctx);

            if (!ctx.SkipElementContent)
            {
                if (!node.IsEmptyElement)
                {
                    VisitChildren(node, ctx);
                }
            }

            handler.ElementEnd(ctx);
            ctx.ElementStack.RemoveAt(ctx.ElementStack.Count - 1);
        }