本文整理汇总了TypeScript中xml.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript xml.default方法的具体用法?TypeScript xml.default怎么用?TypeScript xml.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml
的用法示例。
在下文中一共展示了xml.default方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
test('supports xml attributes', t => {
t.is(xml([{b: {_attr: {}}}]), '<b/>');
t.is(xml([{
a: {
_attr: {
attribute1: 'some value',
attribute2: 12345
}
}
}]), '<a attribute1="some value" attribute2="12345"/>');
t.is(xml([{
a: [{
_attr: {
attribute1: 'some value',
attribute2: 12345
}
}]
}]), '<a attribute1="some value" attribute2="12345"></a>');
t.is(xml([{
a: [{
_attr: {
attribute1: 'some value',
attribute2: 12345
}
}, 'content']
}]), '<a attribute1="some value" attribute2="12345">content</a>');
});
示例2:
test('supports cdata', t => {
t.is(xml([{a: {_cdata: 'This is some <strong>CDATA</strong>'}}]), '<a><![CDATA[This is some <strong>CDATA</strong>]]></a>');
t.is(xml([{
a: {
_attr: {attribute1: 'some value', attribute2: 12345},
_cdata: 'This is some <strong>CDATA</strong>'
}
}]), '<a attribute1="some value" attribute2="12345"><![CDATA[This is some <strong>CDATA</strong>]]></a>');
t.is(xml([{a: {_cdata: 'This is some <strong>CDATA</strong> with ]]> and then again ]]>'}}]), '<a><![CDATA[This is some <strong>CDATA</strong> with ]]]]><![CDATA[> and then again ]]]]><![CDATA[>]]></a>');
});
示例3: xml
data: (() => {
const xmlData = xml(this.formatter.format(file.Document));
const mediaDatas = this.imageReplacer.getMediaData(xmlData, file.Media);
mediaDatas.forEach((mediaData, i) => {
file.DocumentRelationships.createRelationship(
documentRelationshipCount + i,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
`media/${mediaData.fileName}`,
);
});
return xml(this.formatter.format(file.DocumentRelationships));
})(),
示例4: Promise
test('streams end properly', t => {
const elem = xml.element({ _attr: { decade: '80s', locale: 'US'} });
const xmlStream = xml({ toys: elem }, { stream: true });
let gotData = false;
t.plan(7);
elem.push({ toy: 'Transformers' });
elem.push({ toy: 'GI Joe' });
elem.push({ toy: [{name: 'He-man'}] });
elem.close();
xmlStream.on('data', (data: any) => {
t.ok(data);
gotData = true;
});
xmlStream.on('end', () => {
t.ok(gotData);
});
return new Promise((resolve, reject) => {
xmlStream.on('close', () => {
t.ok(gotData);
resolve();
});
xmlStream.on('error', reject);
});
});