Skip to content

Standard Mapping Style

highsource edited this page Feb 28, 2015 · 20 revisions

Standard Mapping Style

Standard mapping style is a mapping style used by Jsonix by default.

Root element

Example.

XML:

<value attribute="check">test</value>

JS:

{
	name : { localPart : "value", namespaceURI : "", prefix : "" },
	value : {
		value : "test",
		attribute : "check"
	}
}

Character content

Value property

Example.

Fragment of the mapping:

{
	name: "value",
	typeInfo: "String",
	type: "value"
}

XML:

<value attribute="check">test</value>

JS:

{
	value : "test"
}

Attributes

Attribute property

Example.

Fragment of the mapping:

{
	name: "string",
	attributeName: "string",
	type: "attribute"
}

XML:

<attribute string="zero" integers="1 2">test</attribute>

JS:

{
	string : "zero"
}

Any attribute property

Example.

Fragment of the mapping:

{
	name: "otherAttributes",
	type: "anyAttribute"
}

XML:

<anyAttribute xmlns:a="urn:a" xmlns:b="urn:b" a:a="a" b:b="b">test</anyAttribute>

JS:

{
	otherAttributes : {
		"{http://www.w3.org/2000/xmlns/}a" : "urn:a",
		"{http://www.w3.org/2000/xmlns/}b" : "urn:b",
		"{urn:a}a" : "a",
		"{urn:b}b" : "b"
	}
}

Elements

Element property

Fragment of the mapping:

{
	type: "element",
	name: "element",
	elementName: "element",
	typeInfo: "String"
}

XML:

<element><element>one</element></element>

JS:

{
	element : "one"
}

Elements property

Fragment of the mapping:

{
	name: "stringOrInteger",
	collection: true,
	elementTypeInfos: [{
		elementName: "string",
		typeInfo: "String"
	}, {
		elementName: "integer",
		typeInfo: "Integer"
	}],
	type: "elements"
}

XML:

<elements><string>one</string><integer>2</integer></elements>

JS:

{
	stringOrInteger : [ "one", 2 ]
}

Element map property

Fragment of the mapping:

{
	name : "element",
	type : "elementMap",
	key : { name : "key", type : "attribute" },
	value : { name : "value", type : "value" }
}

XML:

<elementMap><element key="one">earth</element><element key="two">wind</element></elementMap>

JS:

{
	one : "earth",
	two : "wind"
}

Element reference property

Fragment of the mapping:

{
	name: "base",
	collection: true,
	elementName: "base",
	typeInfo: "Zero.BaseType",
	type: "elementRef"
}

XML:

<elementRef><base><alpha>one</alpha><beta>2</beta></base></elementRef>

JS:

{
	base : [ {
		name : { localPart : "base", namespaceURI : "", prefix : "" },
		value : {
			alpha : "one",
			beta : [ 2 ]
		}
	} ]
}

Element references property

Fragment of the mapping:

{
	name: "alphaOrBeta",
	collection: true,
	elementTypeInfos: [{
		elementName: "beta",
		typeInfo: "Zero.ValueType"
	}, {
		elementName: "alpha",
		typeInfo: "Zero.ValueType"
	}],
	type: "elementRefs"
}

XML:

<elementRefs><alpha>one</alpha><beta>2</beta></elementRefs>

JS:

{
	alphaOrBeta : [ {
		name : { localPart : "alpha", namespaceURI : "", prefix : "" },
		value : {
			value : "one"
		}
	}, {
		name : { localPart : "beta", namespaceURI : "", prefix : "" },
		value : {
			value : "2"
		}
	} ]
}

Any element property

Fragment of the mapping:

{
	name: "any",
	domAllowed: true,
	typedObjectAllowed: true,
	type: "anyElement"
}

XML:

<anyElementLax><string>test</string></anyElementLax>

JS:

{
	any : {
		name : { localPart : "string", namespaceURI : "", prefix : "" },
		value : "test"
	}
}
Clone this wiki locally