예제 #1
0
 public void WriteElement(Element element)
 {
     ElementFlags flags = 0;
     if (element.HasAttributes)
         flags |= ElementFlags.HasAttributes;
     if (element.HasChildren)
         flags |= ElementFlags.HasChildren;
     WriteElement(element.Tag, flags);
     if (element.HasAttributes)
     {
         foreach (Attribute attr in element.Attributes.Keys)
         {
             WriteAttribute(attr, element[attr]);
         }
         WriteTerminator();
     }
     if (element.HasChildren)
     {
         foreach (Element child in element.Children)
         {
             WriteElement(child);
         }
         WriteTerminator();
     }
 }
 //public ResponseMessage(EComMessage.ResponseCode code, string message, string stan)
 //    : base(Tag.Rsp, WbxmlWriter.ElementFlags.HasAttributes)
 //{
 //    this.code = (int)code;
 //    this.displayedMessage = message;
 //    this.printedMessage = message;
 //    this.stan = stan;
 //}
 //// for handshake/login
 //public ResponseMessage(bool sendDateTime)
 //    : base(Tag.Rsp, WbxmlWriter.ElementFlags.HasAttributes)
 //{
 //    this.code = 0;
 //    this.sendDateTime = sendDateTime;
 //}
 public ResponseMessage(Element element)
     : base(Tag.Rsp, WbxmlWriter.ElementFlags.HasAttributes | WbxmlWriter.ElementFlags.HasChildren)
 {
     ConstructFromElement(element);
 }
예제 #3
0
 protected virtual void ConstructFromElement(Element element)
 {
     if (element.HasAttributes)
     {
         foreach (Comtech.Wbxml.Attribute attr in element.Attributes.Keys)
         {
             SetAttribute(attr, element.Attributes[attr]);
         }
     }
     if (element.HasChildren)
     {
         foreach (Element child in element.Children)
         {
             AddChildElement(child);
         }
     }
 }
예제 #4
0
 //public RequestMessage()
 //    : base(Tag.Req, WbxmlWriter.ElementFlags.HasAttributes)
 //{
 //}
 public RequestMessage(Element element)
     : base(Tag.Req, WbxmlWriter.ElementFlags.HasAttributes)
 {
     ConstructFromElement(element);
 }
예제 #5
0
 protected virtual void AddChildElement(Element element)
 {
 }
예제 #6
0
 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;
 }
예제 #7
0
 public static Element ReadFromStream(Stream s, Encoding encoding)
 {
     Element element = new Element();
     return ReadFromStream(s, encoding, element);
 }
예제 #8
0
 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;
 }
예제 #9
0
 public static Element ReadFromXml(XmlElement xmlElement)
 {
     Element element = new Element();
     return ReadFromXml(xmlElement, element);
 }