使用XmlReader类提高XML Msg处理的性能

需求:抽取XML消息中的某些节点值并Promote

XMLDocument类内存消耗比较大,特别对于一些大消息。XmlReader类支持只读,向前顺序读取的方式,内存消耗较小。

实例代码:
           XmlReader bodyXMLDoc = XmlTextReader.Create(oldStream);
           while (bodyXMLDoc.Read())
            {
                switch (bodyXMLDoc.NodeType)
                {
                    case XmlNodeType.Element:
                        {
                            if (bodyXMLDoc.Name == this.SenderID_TagName)
                            {
                              string fileHeaderSendIDValue = bodyXMLDoc.ReadInnerXml();
                              inmsg.Context.Promote("FileHeader_SenderID", this.propertySchemaNS, fileHeaderSendIDValue);
                            }
                        }
                 }
            }

你可能感兴趣的:(reader)