Beispiel #1
0
    public XmlElement ToXml(XmlContext context)
        {
        XmlElement me = context.CreateElement(this.Text);

        switch (this.Type)
            {
        // Text contents
        case NadirParser.MatchClause:
        case NadirParser.NoMatchClause:
        case NadirParser.Adenine:
        case NadirParser.Guanine:
        case NadirParser.Cytosine:
        case NadirParser.Thymine:
            me.AppendChild(context.CreateTextNode(this.GetNadirChild(0)));
            return me;

        // Named thing
        case NadirParser.SeqDesignerDef:
        case NadirParser.ExperimentDef:
        case NadirParser.VariableDef:
        case NadirParser.TypedefDef:
        case NadirParser.AttrDef:
        case NadirParser.FunctionCall:
        case NadirParser.VariableRef:
        case NadirParser.FormalParam:
        case NadirParser.FunctionDef:
            {
            // ^(Name name scope?)
            //
            NadirAST nodeName = this.GetNadirChild(0);
            me.Attributes.Append(context.CreateAttribute("name", nodeName, 0));
            if (nodeName.ChildCount > 1)
                me.Attributes.Append(context.CreateAttribute("scope", nodeName, 1));
            //
            int iChildFirst = 1;
            //
            // Recurse on remaining children
            //
            for(int i=iChildFirst; i < this.ChildCount; i++)
                {
                me.AppendChild(this.GetNadirChild(i).ToXml(context));
                }
            //
            return me;
            }

        case NadirParser.DomainDefRef:
            {
            XmlAttribute attr = context.Document.CreateAttribute("name");
            attr.InnerText = this.GetNadirChild(0).Text;
            me.Attributes.Append(attr);
            return me;
            }

        // Just me and my children
        default:
            //
            for(int i=0; i < this.ChildCount; i++)
                me.AppendChild(this.GetNadirChild(i).ToXml(context));
            //
            return me;        
            }
        }