Skip to content

Commit 46523dc

Browse files
nikkufake-join[bot]
authored andcommitted
feat: access :xmlns as global name
1 parent 6912fed commit 46523dc

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

lib/read.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ ElementHandler.prototype.createElement = function(node) {
343343
if (prop) {
344344
value = coerceType(prop.type, value);
345345
} else
346-
if (name !== 'xmlns') {
346+
if (name === 'xmlns') {
347+
name = ':' + name;
348+
} else {
347349
propNameNs = parseNameNS(name, descriptor.ns.prefix);
348350

349351
// check whether attribute is defined in a well-known namespace

test/helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function createModelBuilder(base) {
2626
throw new Error('[test-util] must specify a base directory');
2727
}
2828

29-
function createModel(packageNames) {
29+
function createModel(packageNames, options = {}) {
3030

3131
var packages = map(packageNames, function(f) {
3232
var pkg = cache[f];
@@ -43,7 +43,7 @@ export function createModelBuilder(base) {
4343
return pkg;
4444
});
4545

46-
return new Moddle(packages);
46+
return new Moddle(packages, { strict: true, ...options });
4747
}
4848

4949
return createModel;

test/spec/writer.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ describe('Writer', function() {
126126
// given
127127
var writer = createWriter(datatypesModel);
128128

129-
var root = datatypesModel.create('dt:Root', { xmlns: 'http://datatypes' });
129+
var root = datatypesModel.create('dt:Root', { ':xmlns': 'http://datatypes' });
130130

131131
root.set('bounds', datatypesModel.create('dt:Rect', { y: 100 }));
132132

@@ -865,7 +865,7 @@ describe('Writer', function() {
865865
// given
866866
var writer = createWriter(extendedModel);
867867

868-
var root = extendedModel.create('props:Root', { xmlns: 'http://properties' });
868+
var root = extendedModel.create('props:Root', { ':xmlns': 'http://properties' });
869869

870870
// when
871871
var xml = writer.toXML(root);
@@ -880,7 +880,7 @@ describe('Writer', function() {
880880
// given
881881
var writer = createWriter(extendedModel);
882882

883-
var root = extendedModel.create('props:Root', { xmlns: 'http://properties', id: 'Root' });
883+
var root = extendedModel.create('props:Root', { ':xmlns': 'http://properties', id: 'Root' });
884884

885885
var any = root.get('any');
886886
any.push(extendedModel.create('ext:ExtendedComplex'));
@@ -904,7 +904,7 @@ describe('Writer', function() {
904904
var writer = createWriter(extendedModel);
905905

906906
var root = extendedModel.create('props:Root', {
907-
xmlns: 'http://properties',
907+
':xmlns': 'http://properties',
908908
'xmlns:foo': 'http://fooo',
909909
id: 'Root',
910910
'foo:bar': 'BAR'
@@ -1459,7 +1459,7 @@ describe('Writer', function() {
14591459
var root = extensionModel.create('e:Root', {
14601460

14611461
// unprefixed root namespace
1462-
'xmlns': 'http://extensions',
1462+
':xmlns': 'http://extensions',
14631463
extensions: [
14641464
extensionModel.createAny('bar:bar', 'http://bar', {
14651465
'xmlns:bar': 'http://bar',
@@ -1510,7 +1510,7 @@ describe('Writer', function() {
15101510
var root = extensionModel.create('e:Root', {
15111511

15121512
// unprefixed root namespace
1513-
'xmlns': 'http://extensions',
1513+
':xmlns': 'http://extensions',
15141514
extensions: [
15151515
extensionModel.createAny('bar:bar', 'http://bar', {
15161516
'xmlns:bar': 'http://bar',
@@ -1540,7 +1540,7 @@ describe('Writer', function() {
15401540
var root = extensionModel.create('e:Root', {
15411541

15421542
// unprefixed root namespace
1543-
'xmlns': 'http://extensions',
1543+
':xmlns': 'http://extensions',
15441544
'xmlns:bar': 'http://bar',
15451545
extensions: [
15461546
extensionModel.createAny('bar:bar', 'http://bar', {
@@ -1571,7 +1571,7 @@ describe('Writer', function() {
15711571
var root = extensionModel.create('e:Root', {
15721572

15731573
// unprefixed root namespace
1574-
'xmlns': 'http://extensions',
1574+
':xmlns': 'http://extensions',
15751575
'xmlns:otherBar': 'http://bar',
15761576
'xmlns:otherFoo': 'http://foo',
15771577
extensions: [
@@ -1606,7 +1606,7 @@ describe('Writer', function() {
16061606
var root = extensionModel.create('e:Root', {
16071607

16081608
// unprefixed root namespace
1609-
'xmlns': 'http://extensions',
1609+
':xmlns': 'http://extensions',
16101610
'xmlns:otherBar': 'http://bar',
16111611
extensions: [
16121612
extensionModel.createAny('bar:bar', 'http://bar', {
@@ -1636,12 +1636,12 @@ describe('Writer', function() {
16361636
var root = extendedModel.create('props:Root', {
16371637

16381638
// unprefixed top-level namespace
1639-
'xmlns': 'http://properties',
1639+
':xmlns': 'http://properties',
16401640
any: [
16411641
extendedModel.create('ext:ExtendedComplex', {
16421642

16431643
// unprefixed nested namespace
1644-
'xmlns': 'http://extended'
1644+
':xmlns': 'http://extended'
16451645
})
16461646
]
16471647
});
@@ -1667,13 +1667,13 @@ describe('Writer', function() {
16671667
var root = extendedModel.create('ext:Root', {
16681668

16691669
// unprefixed top-level namespace
1670-
'xmlns': 'http://extended',
1670+
':xmlns': 'http://extended',
16711671
id: 'ROOT',
16721672
any: [
16731673
extendedModel.create('props:Complex', {
16741674

16751675
// unprefixed nested namespace
1676-
'xmlns': 'http://properties'
1676+
':xmlns': 'http://properties'
16771677
})
16781678
]
16791679
});
@@ -1707,7 +1707,7 @@ describe('Writer', function() {
17071707
'xmlns:a' : 'http://datatypes-aliased',
17081708
otherBounds: [
17091709
model.create('dt:Rect', {
1710-
'xmlns': 'http://datatypes',
1710+
':xmlns': 'http://datatypes',
17111711
y: 100
17121712
})
17131713
]
@@ -1731,11 +1731,11 @@ describe('Writer', function() {
17311731
var writer = createWriter(extendedModel);
17321732

17331733
var root = extendedModel.create('ext:Root', {
1734-
xmlns: 'http://extended',
1734+
':xmlns': 'http://extended',
17351735
id: 'Root',
17361736
'xmlns:props': 'http://properties',
17371737
any: [
1738-
extendedModel.create('props:Base', { xmlns: 'http://properties' })
1738+
extendedModel.create('props:Base', { ':xmlns': 'http://properties' })
17391739
]
17401740
});
17411741

@@ -1787,7 +1787,7 @@ describe('Writer', function() {
17871787
id: 'ComplexNesting',
17881788
nested: [
17891789
extendedModel.create('props:ComplexNesting', {
1790-
xmlns: 'http://properties',
1790+
':xmlns': 'http://properties',
17911791
nested: [
17921792
extendedModel.create('props:ComplexNesting', {
17931793
nested: [
@@ -1839,7 +1839,7 @@ describe('Writer', function() {
18391839
'xmlns:ext': 'http://extended',
18401840
any: [
18411841
model.create('props:ComplexNesting', {
1842-
'xmlns': 'http://properties',
1842+
':xmlns': 'http://properties',
18431843
nested: [
18441844
model.create('ext:ExtendedComplex', { numCount: 1 })
18451845
]

0 commit comments

Comments
 (0)