當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript xml.default方法代碼示例

本文整理匯總了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>');
});
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:27,代碼來源:xml-tests.ts

示例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>');
});
開發者ID:ArtemZag,項目名稱:DefinitelyTyped,代碼行數:10,代碼來源:xml-tests.ts

示例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));
                })(),
開發者ID:dolanmiu,項目名稱:docx,代碼行數:14,代碼來源:next-compiler.ts

示例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);
    });
});
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:xml-tests.ts


注:本文中的xml.default方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。