moddle-xml
Advanced tools
Comparing version 0.7.0 to 0.8.0
@@ -36,2 +36,14 @@ 'use strict'; | ||
module.exports.XSI_TYPE = 'xsi:type'; | ||
var XSI_TYPE = module.exports.XSI_TYPE = 'xsi:type'; | ||
function serializeFormat(element) { | ||
return element.xml && element.xml.serialize; | ||
} | ||
module.exports.serializeAsType = function(element) { | ||
return serializeFormat(element) === XSI_TYPE; | ||
}; | ||
module.exports.serializeAsProperty = function(element) { | ||
return serializeFormat(element) === 'property'; | ||
}; |
@@ -19,2 +19,3 @@ 'use strict'; | ||
XSI_URI = common.DEFAULT_NS_MAP.xsi, | ||
serializeAsType = common.serializeAsType, | ||
aliasToName = common.aliasToName; | ||
@@ -327,3 +328,3 @@ | ||
if (property.serialize === XSI_TYPE) { | ||
if (serializeAsType(property)) { | ||
typeAnnotation = node.attributes[XSI_TYPE]; | ||
@@ -330,0 +331,0 @@ |
@@ -12,3 +12,5 @@ 'use strict'; | ||
common = require('./common'), | ||
nameToAlias = common.nameToAlias; | ||
nameToAlias = common.nameToAlias, | ||
serializeAsType = common.serializeAsType, | ||
serializeAsProperty = common.serializeAsProperty; | ||
@@ -331,3 +333,4 @@ var XML_PREAMBLE = '<?xml version="1.0" encoding="UTF-8"?>\n', | ||
// rather than element name | ||
var asType = p.serialize === XSI_TYPE; | ||
var asType = serializeAsType(p), | ||
asProperty = serializeAsProperty(p); | ||
@@ -339,2 +342,5 @@ forEach(value, function(v) { | ||
serializer = new TypeSerializer(self, ns); | ||
} else | ||
if (asProperty) { | ||
serializer = new ElementSerializer(self, ns); | ||
} else { | ||
@@ -606,2 +612,2 @@ serializer = new ElementSerializer(self); | ||
module.exports = XMLWriter; | ||
module.exports = XMLWriter; |
{ | ||
"name": "moddle-xml", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "XML import/export for documents described with moddle", | ||
@@ -5,0 +5,0 @@ "directories": { |
@@ -12,4 +12,4 @@ { | ||
"properties": [ | ||
{ "name": "bounds", "serialize": "xsi:type", "type": "Rect" }, | ||
{ "name": "otherBounds", "type": "Rect", "serialize": "xsi:type", "isMany": true } | ||
{ "name": "bounds", "type": "Rect", "xml": { "serialize" : "xsi:type" } }, | ||
{ "name": "otherBounds", "type": "Rect", "xml": { "serialize" : "xsi:type" }, "isMany": true } | ||
] | ||
@@ -16,0 +16,0 @@ }, |
@@ -19,3 +19,3 @@ { | ||
"properties": [ | ||
{ "name": "attrs", "type": "Attributes", "serialize": "xsi:type" } | ||
{ "name": "attrs", "type": "Attributes", "xml": { "serialize" : "xsi:type" } } | ||
] | ||
@@ -27,3 +27,3 @@ }, | ||
"properties": [ | ||
{ "name": "attrs", "type": "Attributes", "isMany": true, "serialize": "xsi:type" } | ||
{ "name": "attrs", "type": "Attributes", "isMany": true, "xml": { "serialize" : "xsi:type" } } | ||
] | ||
@@ -62,4 +62,4 @@ }, | ||
"name": "someBody", | ||
"serialize": "xsi:type", | ||
"type": "SimpleBody" | ||
"type": "SimpleBody", | ||
"xml": { "serialize" : "xsi:type" } | ||
} | ||
@@ -88,2 +88,9 @@ ] | ||
{ | ||
"name": "WithProperty", | ||
"superClass": [ "Base" ], | ||
"properties": [ | ||
{ "name": "propertyName", "type": "Base", "xml": { "serialize" : "property" } } | ||
] | ||
}, | ||
{ | ||
"name": "Base" | ||
@@ -192,2 +199,2 @@ }, | ||
] | ||
} | ||
} |
@@ -351,3 +351,22 @@ 'use strict'; | ||
it('property name', function() { | ||
// given | ||
var writer = createWriter(model); | ||
var propertyValue = model.create('props:BaseWithId', { id: 'PropertyValue' }); | ||
var container = model.create('props:WithProperty', { propertyName: propertyValue }); | ||
// when | ||
var xml = writer.toXML(container); | ||
var expectedXml = | ||
'<props:withProperty xmlns:props="http://properties">' + | ||
'<props:propertyName id="PropertyValue" />' + | ||
'</props:withProperty>'; | ||
// then | ||
expect(xml).to.eql(expectedXml); | ||
}); | ||
it('collection', function() { | ||
@@ -943,2 +962,2 @@ | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
114330
3264