public static Element ReadFromStream(Stream s, Encoding encoding, Element element)
 {
     byte token = ReadByte(s, "element token");
     byte tagId = (byte)(token & 0x3F); // reset WBXML "tag with attributes" bit and "tag with content" bit
     if (tagId < 5)
         throw new ApplicationException(String.Format("expected element token, found {0} at {1}", token.ToString("X2"), s.Position));
     element.tag = (Tag)tagId;
     if ((token & 0x80) != 0)
     {
         element.attributes = new AttributeList();
         element.ReadAttributes(s, encoding);
     }
     if ((token & 0x40) != 0)
     {
         element.children = new List<Element>();
         element.ReadContent(s, encoding);
     }
     return element;
 }
 public static Element ReadFromXml(XmlElement xmlElement, Element element)
 {
     element.tag = GetTagByName(xmlElement.LocalName);
     if (xmlElement.Attributes.Count > 0)
     {
         element.attributes = new AttributeList();
         element.ReadAttributes(xmlElement.Attributes);
     }
     if (xmlElement.ChildNodes.Count > 0)
     {
         element.children = new List<Element>();
         element.ReadContent(xmlElement.ChildNodes);
     }
     return element;
 }