Controlling Validation

Problem

Sometimes you may want read or write XML that is not completely valid against the XSD schema. There are a number of rational's behind this, you may want to save a half completed document, then re-load it, or a 3rd party may supply you data that is not quite valid. Whatever your reason, this section describes the control you have over the validation when reading and writing XML.

See links below for full API descriptions.

Reading XML

The following examples show how to ignore Unknown Attributes and Elements when reading in XML from a file. This may be useful if a customer send XML that is not valid against the schema, but you still want the ability to process the document.

Note: When the document is written out (ToXml...), the unknown Attributes and Elements will be omit as these are not stored within the data binding objects.

  C++

PriceEnquirySampleLib::CQuoteRequestPtr spElm = PriceEnquirySampleLib::CQuoteRequest::CreateInstance();

LtXmlLib16::CXmlSerializationContext& ctx = LtXmlLib16::CXmlSerializationContext::GetDefaultContext();

ctx.SetIgnoreUnknownAttributes(true);
ctx.SetIgnoreUnknownElements(true);

elm->FromXmlFile(lpctFilename, ctx);

  C#
PriceEnquirySampleLib.QuoteRequest elm = new PriceEnquirySampleLib.QuoteRequest();

LiquidTechnologies.Runtime.Net40.XmlSerializationContext ctx = LiquidTechnologies.Runtime.Net40.XmlSerializationContext.Default;

ctx.IgnoreUnknownAttributes = true;
ctx.IgnoreUnknownElements = true;

elm.FromXmlFile(filename, ctx);

  Java

PriceEnquirySampleLib.QuoteRequest elm = new PriceEnquirySampleLib.QuoteRequest();
XmlSerializationContext ctx = XmlSerializationContext.Default;

ctx.setIgnoreUnknownAttributes(true);
ctx.setIgnoreUnknownElements(true);

elm.fromXmlFile(filename, ctx);

  Visual Basic

Dim oElm As PriceEnquiryLib.QuoteRequest
Dim ctx As LtXmlComLib16.XmlSerializationContext

Set oElm = New PriceEnquiryLib.QuoteRequest
Set ctx = LtXmlComLib16.DefaultXmlSerializationContext

ctx.IgnoreUnknownAttributes = True
ctx.IgnoreUnknownElements = True

oElm.FromXmlFile filename, ctx

 

Notes

Description Value
Article Created 28/6/2006
Versions Liquid XML 2005 (5.0.0) and greater
Also See C++ API, C# API, Java API, VB6 API, Controlling the exported XML