Esempio n. 1
0
 string XMLSerialize(object oResult)
 // http://msdn.microsoft.com/en-us/library/58a18dwa(v=VS.100).aspx
     {
     IXmlWritable wResult = oResult as IXmlWritable;
     if (wResult != null)
         {
         XmlSerializer ser = new XmlSerializer(typeof(XmlElement));
         TextWriter writer = new Utf8StringWriter();
         XmlContext context = new XmlContext();
         //
         context.Document = new XmlDocument();
         //
         XmlElement wElement = wResult.ToXml(context);;
         //
         XmlElement rootElement = context.CreateElement("Root");
         rootElement.Attributes.Append(context.CreateAttribute("randSeed", MiscUtil.RandSeed));
         rootElement.AppendChild(wElement);
         //
         context.Document.AppendChild(rootElement);
         //
         ser.Serialize(writer, context.Document);
         writer.Close();
         return writer.ToString();
         }
     return null;
     }
Esempio n. 2
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;        
            }
        }
Esempio n. 3
0
 public override XmlElement ToXml(XmlContext context)
     {
     XmlElement me = context.CreateElement("Domain");
     me.Attributes.Append(context.CreateXmlIdAttribute(this));
     me.Attributes.Append(context.CreateAttribute("domid", this.Id));
     //
     if (this.Symbol != null)
         {
         me.Attributes.Append(context.CreateAttribute("name", this.Symbol.DisplayName));
         }
     //
     if (this.IsConnected)
         {
         me.Attributes.Append(context.CreateAttribute("connection", context.XmlIdOf(this.Connection)));
         }
     //
     if (this.IsComplemented)
         {
         me.Attributes.Append(context.CreateAttribute("complemented", "true"));
         }
     //
     // Deal with extended attributes that we didn't print by the above means.
     // REVIEW: we could do better - try to unify the builtin and non-builtin attrs.
     //
     foreach (KeyValuePair<string,EvaluateAttributeOnce> pair in this.DefinedAttrs)
         {
         XmlElement domattr = context.CreateElement("DomainAttribute");
         domattr.Attributes.Append(context.CreateAttribute("name", pair.Key));
         domattr.Attributes.Append(context.CreateAttribute("value", pair.Value.AttributeValue));
         me.AppendChild(domattr);
         }
     //
     if (this.Nucleotides!=null && this.Nucleotides.Length > 0)
         {
         me.Attributes.Append(context.CreateAttribute("sequence", this.Nucleotides));
         }
     //
     return me;
     }