Class XmlUnmarshallerContext
Wrap an XmltextReader
for simulating an event stream.
Each Read()
operation goes either to the next element or next attribute within
the current element. TestExpression()
is used to match the current event
to an xpath expression. The general pattern looks like this:
UnmarshallerContext context = new UnmarshallerContext(...);
while (context.Read())
{
if (context.TestExpresion("path/to/element"))
{
myObject.stringMember = stringUnmarshaller.GetInstance().Unmarshall(context);
continue;
}
if (context.TestExpression("path/to/@attribute"))
myObject.MyComplexTypeMember = MyComplexTypeUnmarshaller.GetInstance().Unmarshall(context);
}
public class XmlUnmarshallerContext : UnmarshallerContext, IDisposable
- Inheritance
-
XmlUnmarshallerContext
- Implements
- Derived
- Inherited Members
Constructors
XmlUnmarshallerContext(Stream, bool, IWebResponseData, bool)
Wrap an XmlTextReader with state for event-based parsing of an XML stream.
public XmlUnmarshallerContext(Stream responseStream, bool maintainResponseBody, IWebResponseData responseData, bool isException = false)
Parameters
responseStream
StreamStream
with the XML from a service response.maintainResponseBody
boolIf set to true, maintains a copy of the complete response body constraint to log response size as the stream is being read.
responseData
IWebResponseDataResponse data coming back from the request
isException
boolIf set to true, maintains a copy of the complete response body as the stream is being read.
XmlUnmarshallerContext(Stream, bool, IWebResponseData, bool, IRequestContext)
Wrap an XmlTextReader with state for event-based parsing of an XML stream.
public XmlUnmarshallerContext(Stream responseStream, bool maintainResponseBody, IWebResponseData responseData, bool isException, IRequestContext requestContext)
Parameters
responseStream
StreamStream
with the XML from a service response.maintainResponseBody
boolIf set to true, maintains a copy of the complete response body constraint to log response size as the stream is being read.
responseData
IWebResponseDataResponse data coming back from the request
isException
boolIf set to true, maintains a copy of the complete response body as the stream is being read.
requestContext
IRequestContextContext for the request that produced this response
Properties
AllowEmptyElementLookup
Lookup of element names that are not skipped if empty within the XML response structure.
public HashSet<string> AllowEmptyElementLookup { get; }
Property Value
CurrentDepth
Returns the element depth of the parser's current position in the XML document being parsed.
public override int CurrentDepth { get; }
Property Value
CurrentPath
The current XML path that is being unmarshalled.
public override string CurrentPath { get; }
Property Value
IsAttribute
True if NodeType
is Attribute
.
public bool IsAttribute { get; }
Property Value
IsEndElement
True if NodeType
is EndElement
.
public override bool IsEndElement { get; }
Property Value
IsStartElement
True if NodeType
is Element
.
public override bool IsStartElement { get; }
Property Value
IsStartOfDocument
True if the context is at the start of the document.
public override bool IsStartOfDocument { get; }
Property Value
Stream
public Stream Stream { get; }
Property Value
Methods
Dispose(bool)
protected override void Dispose(bool disposing)
Parameters
disposing
bool
Read()
Reads to the next node in the XML document, and updates the context accordingly.
public override bool Read()
Returns
- bool
True if a node was read, false if there are no more elements to read./
ReadText()
Returns the text contents of the current element being parsed.
public override string ReadText()
Returns
- string
The text contents of the current element being parsed.