本文整理匯總了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);
});
});