Summary
TXmlDeserializer is a specialized TDeserializer class type for reading values from XML documents, using standard VCL XML classes, such as TXmlDocument. Usually, TXmlDeserializer reads XML documents, which has been previously generated by NG.Serialization.Xml.TXmlSerializer object.
Syntax
TXmlDeserializer = class(TDeserializer)
Constructors
Name | Description | |
Create(IXMLDocument) | ||
Create(IXMLNode) |
Methods
Name | Description | |
DoBeginArray | ||
DoBeginObject | ||
DoEndArray | ||
DoEndObject | ||
DoIsNull | ||
DoNext | ||
DoRead | ||
DoSkip |
Remarks
TXmlDeserializer object should be created providing a reference to existing IXMLNode object from which all de-serializing data values will be read. Each de-serializing should exist in the XML document as a child of provided IXMLNode object. TXmlDeserializer treats XML document as an ordered document, so, first de-serializing value will be read from the first, child of provided IXMLNode object, consd value - from second child, and so on.
TXmlDeserializer is able to skip formatting white-space of formatted XML documents. Formatting write-space is usually added to XML document to make it more readable. White-space is stored in additional text nodes as a text, containing spaces, tabs and line breaks only; TXmlDocument will generate formatted XML, only if doNodeAutoIndent option is included in its Options.
If a value, which need to be de-serialized, has been previously serialized as a root document node (look at NG.Serialization.Xml.TXmlSerializer description to learn how it can be done), TXmlDocument.Node should be used as the constructor argument while creating TXmlDeserializer object. For example, the following XML:
Xml | Copy Code |
---|---|
<Book> <Tittle>Delphi XE Handbook</Tittle> <Author>Marco Cantu</Author> </Book> |
Delphi | Copy Code |
---|---|
xml := TXmlDocument.Create('Book.xml'); xml.Active := True; dsr := TXmlDeserializer.Create(xml.Node); try book := dsr.Value<TBook>; finally dsr.Free; end; |
Examples
Delphi | Copy Code |
---|---|
xml := TXmlDocument.Create('Books.xml'); xml.Active := True; rootNode := xml.ChildNodes['Books']; dsr := TXmlDeserializer.Create(rootNode); try while dsr.HasNext do books.Add(dsr.Value<TBook>); finally szr.Free; end; |
See Also
Reference
- NG.Serialization.Xml.TXmlSerializer
- TSerializer
- TDeserializer
- NG.Serialization.Xml Namespace