Liquid XML Data Binder (C++, Java, VB6) / Reference / C++ / Reference / CAttribute / C++ FromXml - CXmlObjectBase
In This Topic
    C++ FromXml - CXmlObjectBase
    In This Topic
    void FromXml(LPCSTR lpszXMLIn)
    void FromXml(LPCWSTR lpszXMLIn)
    void FromXml(LPCSTR lpszXMLIn, const CSerializationContext& context)
    void FromXml(LPCWSTR lpszXMLIn, const CSerializationContext& context)
      Property Description  
        Method Name FromXml  
        Argument - lpszXMLIn A string containing the XML to be loaded into the object. There is a UNICODE and multibyte version of each overload.  
        Argument - context

    The CSerializationContext object controls the way in which XML is serialized/de-serialized. Its main role is to control the way in which validation is performed and which namespaces are output.
    If this is not specified, the a default (CSerializationContext::Default global static) instance of the class is used. If you are using several libraries generated from different schemas, or you want to change the way validation is performed for during the lifetime of the application or you are writing multithreaded code, then you should consider creating your own instance(s) of the CSerializationContext.

    Note: If you are writing a multithreaded app it is highly recommended that you use a different instance of this class on each thread, as access to the static instance is not synchronized. Although read only operations to the static instance (CSerializationContext::Default) of the class are thread safe, if the global instance CSerializationContext::Default is modified, then this could potentially cause threading problems.

        Description De-Serializes an XML string into the current object.  

    This method will only load XML that complies with the XSD schema.
    It will raise an exception if the XML is invalid.

    The root element in the XML held within lpszXMLIn must correspond to the class which this method is being called on. So you have a simple schema.

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs=""
      <xs:element name="Person">
            <xs:element name="name" type="xs:string"/>
            <xs:element name="Address">
                  <xs:element name="HouseNumber" type="xs:string"/>
                  <xs:element name="PostCode" type="xs:string"/>

    This would cause 2 classes to be generated CPerson & CAddress.
    So if you had the XML Data.

    <?xml version="1.0" encoding="UTF-8"?>
      <name>Joe Blogs</name>
        <PostCode>LS5 9PQ</PostCode>

    You would call FromXml on a CPerson object i.e.

    std::tstring strXML = ... XML data ...
    CPersonPtr spPerson = CPerson::CreateInstance();

    Character encoding.
    The underlying parser is expat version 1.95.6, as supports the following character encodings

    • UTF-8
    • UTF-16

    Note - If you are working with a UNICODE build and UTF-8 encoded data.
    This issue does not relate directly to our product, but has come up a number of times and is worth noting. UTF-8 (or other similar) encoded data should not be held in a UNICODE string. Attempting to convert a UTF-8 encoded string to UNICODE can damage the data (UTF-8 uses all the values 0-255 to encode the data, some of this range is not valid in UNICODE, so attempting the conversion results in '?' being substituted for invalid chars).
    If you are not familiar with char encoding's, and this is possibly going to be an issue, then we recommend that within your application you consider XML data to be binary in nature, and use the FromXmlStream method.

    See Multi-Language Support and Global Functions for more information.