CrystalXmlOutputAttribute

Namespace: SnowBank.Data.Xml · class

Implements: CrystalOutputAttribute

Requests XML output from a CrystalConverterAttribute container, and carries the parameters of that format

Remarks

Applied on the same partial container class that carries [CrystalConverter] and one or more [CrystalSerializable(...)] attributes. When present, the generator emits a WriteXml<TEmitter> body and the XML output methods (ToXmlText, ToXmlSlice, ToXmlBytes, WriteXmlTo, ToXDocument) for each generated type.

Combine it with [CrystalJsonOutput] on the same container to produce both formats from one set of registered types; alone, the container produces XML and nothing else. It does not combine with the mono-format [CrystalJsonConverter] alias (CRYS0002).

XML output is strictly opt-in: a container that never names this attribute produces no XML.

Constructors

CrystalXmlOutputAttribute

CrystalXmlOutputAttribute()

Enables XML output for this serializer container, deriving all defaults from the container's JSON profile

CrystalXmlOutputAttribute(CrystalXmlSerializerDefaults defaults)

Enables XML output for this serializer container

  • defaults — Default settings used for the generated converters

Properties

DictionaryFormat

CrystalXmlDictionaryFormat DictionaryFormat { get; set; }

Default representation for dictionary-like members of this container that do not override it with DictionaryFormat

OmitNamespaces

bool OmitNamespaces { get; set; }

Strips namespaces and prefixes from the DataContractCompat output, keeping the rest of that format

Under this option the DataContract profile writes no XML declaration, no prefix and no xmlns, ever: element names keep their local name only, the nil and type attributes are written bare, and a type value is the local contract name with no namespace half. Everything else about the format is unchanged, which is the point: the null markers, the member order, the lexical forms and the KeyValueOfXY entries all stay.

It exists for one reason: an application whose stored documents were written by a namespace-free writer reads them back by local name. A namespaced document would not match. So this is the output to name when the documents already exist, and the default is the output to name for anything new.

What it costs: type="RangeCriterion" has lost the namespace half of its qualified name, so two derived types with the same local name in different contract namespaces become the same annotation in the output.

Generation-time, like the CrystalXmlSerializerDefaults preset: the generated code bakes its names as frozen literals, so a name exists with a namespace or without one and never both. On General, which has no namespaces to strip, the option does nothing and the generator says so (CXML0012).