XML : manual xmlstream parsing to object

I have this xml parsing logic:

      public void InitFrameAck(XmlReader reader)      {          if (!reader.IsStartElement())          {              Version = reader.GetAttribute("version");              reader.Read(); //read the next element          }          if (!reader.IsStartElement())          {              TagError = reader.ReadElementString("tagerror");              reader.Read();          }          if (!reader.IsStartElement())              ErrorDescription = reader.ReadElementString("errordescription");      }    

Not every message I receive contains all properties so I'm checking every time if I received the end tag of the root element. So I don't read something that doesn't exists in that particular message. Is there any other method I don't need to check every time if I have received an end element. Or a global condition because I can't think of one.

N.B. I will not use the built in XmlSerializer because it is too slow. That's why I'm using this method for xml deserialzing.

No comments:

Post a Comment