示例
@xmldom/xmldom 0.8.13: XMLSerializer
已验证示例 — npm @xmldom/xmldom 0.8.13: XMLSerializer. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: XMLSerializer instance serializes a DOM Document…
sha256:0d23ff0511e419682567775db4692666b7ad3ebf770108957c97f0f47be7c87e
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 2
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 npm
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-23 |
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-07 |
案例
HOW- 目标
- verify @xmldom/xmldom.XMLSerializer in pkg:npm/%40xmldom/xmldom@0.8.13
- 符号
-
- @xmldom/xmldom.XMLSerializer
- 创建时间
- 2026-08-23T14:04:49Z
契约
- XMLSerializer instance serializes a DOM Document node with elements, attributes, and text into a well-formed XML string
- XMLSerializer serializes individual DOM Element and DocumentFragment nodes into XML string representations
- XMLSerializer serializes Comment, CDATASection, and Text nodes accurately preserving their content
- XMLSerializer correctly serializes XML namespaces and escapes special characters in attributes and text
- XMLSerializer correctly formats self-closing empty XML elements
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
源代码
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify @xmldom/xmldom.XMLSerializer in pkg:npm/%40xmldom/xmldom@0.8.13
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40xmldom/xmldom@0.8.13
Demonstrate these symbols/APIs:
- @xmldom/xmldom.XMLSerializer
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:b96c754bc31126b2c577b04536bc727931689998d9e9ab9415544499fd746513","contract":["XMLSerializer instance serializes a DOM Document node with elements, attributes, and text into a well-formed XML string","XMLSerializer serializes individual DOM Element and DocumentFragment nodes into XML string representations","XMLSerializer serializes Comment, CDATASection, and Text nodes accurately preserving their content","XMLSerializer correctly serializes XML namespaces and escapes special characters in attributes and text","XMLSerializer correctly formats self-closing empty XML elements"],"goal":"verify @xmldom/xmldom.XMLSerializer in pkg:npm/%40xmldom/xmldom@0.8.13","kind":"HOW","packages":["pkg:npm/%40xmldom/xmldom@0.8.13"],"schemaVersion":1,"symbols":["@xmldom/xmldom.XMLSerializer"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40xmldom/xmldom@0.8.13"],"schemaVersion":1,"subject":"pkg:npm/%40xmldom/xmldom@0.8.13","symbols":["@xmldom/xmldom.XMLSerializer"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-xmldom-xmlserializer",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-xmldom-xmlserializer",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@xmldom/xmldom": "0.8.13"
}
},
"node_modules/@xmldom/xmldom": {
"version": "0.8.13",
"resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.13.tgz",
"integrity": "sha512-KRYzxepc14G/CEpEGc3Yn+JKaAeT63smlDr+vjB8jRfgTBBI9wRj/nkQEO+ucV8p8I9bfKLWp37uHgFrbntPvw==",
"license": "MIT",
"engines": {
"node": ">=10.0.0"
}
}
}
}
{
"name": "sample-xmldom-xmlserializer",
"version": "1.0.0",
"private": true,
"type": "module",
"license": "MIT-0",
"dependencies": {
"@xmldom/xmldom": "0.8.13"
}
}
{
"schemaVersion": 1,
"goal": "verify @xmldom/xmldom.XMLSerializer in pkg:npm/%40xmldom/xmldom@0.8.13",
"kind": "HOW",
"packages": [
"pkg:npm/%40xmldom/xmldom@0.8.13"
],
"symbols": [
"@xmldom/xmldom.XMLSerializer"
]
}
import { XMLSerializer, DOMParser } from '@xmldom/xmldom';
export function createSerializer() {
return new XMLSerializer();
}
export function serializeNode(node) {
const serializer = new XMLSerializer();
return serializer.serializeToString(node);
}
export function parseAndSerialize(xmlString, mimeType = 'text/xml') {
const parser = new DOMParser();
const doc = parser.parseFromString(xmlString, mimeType);
const serializer = new XMLSerializer();
return serializer.serializeToString(doc);
}
import assert from 'node:assert/strict';
import { DOMParser, XMLSerializer } from '@xmldom/xmldom';
import {
createSerializer,
serializeNode,
parseAndSerialize
} from '../src/index.mjs';
const parser = new DOMParser();
const serializer = createSerializer();
// Assertion 1: XMLSerializer instance serializes a DOM Document node with elements, attributes, and text into a well-formed XML string
{
const xml = '<catalog><book id="bk101"><title>XML Developers Guide</title><price>44.95</price></book></catalog>';
const doc = parser.parseFromString(xml, 'text/xml');
const serialized = serializer.serializeToString(doc);
assert.equal(serialized, xml, 'Document serialization should match original XML');
assert.equal(parseAndSerialize(xml), xml, 'parseAndSerialize should produce identical output');
}
// Assertion 2: XMLSerializer serializes individual DOM Element and DocumentFragment nodes into XML string representations
{
const xml = '<root><header>Header Text</header><content>Body Text</content></root>';
const doc = parser.parseFromString(xml, 'text/xml');
const headerElem = doc.getElementsByTagName('header')[0];
const headerXml = serializeNode(headerElem);
assert.equal(headerXml, '<header>Header Text</header>', 'Element serialization should produce element XML');
const docFrag = doc.createDocumentFragment();
const fragChild = doc.createElement('fragment-item');
fragChild.setAttribute('status', 'active');
fragChild.textContent = 'Fragment Content';
docFrag.appendChild(fragChild);
const fragXml = serializer.serializeToString(docFrag);
assert.equal(fragXml, '<fragment-item status="active">Fragment Content</fragment-item>', 'DocumentFragment serialization should serialize child elements');
}
// Assertion 3: XMLSerializer serializes Comment, CDATASection, and Text nodes accurately preserving their content
{
const xml = '<container><!-- A valid comment --><![CDATA[<raw-data>&value</raw-data>]]><info>Sample text</info></container>';
const doc = parser.parseFromString(xml, 'text/xml');
const serialized = serializer.serializeToString(doc);
assert.ok(serialized.includes('<!-- A valid comment -->'), 'Comment should be serialized correctly');
assert.ok(serialized.includes('<![CDATA[<raw-data>&value</raw-data>]]>'), 'CDATASection should be serialized correctly');
assert.ok(serialized.includes('<info>Sample text</info>'), 'Text node in element should be serialized correctly');
}
// Assertion 4: XMLSerializer correctly serializes XML namespaces and escapes special characters in attributes and text
{
const xml = '<ns:root xmlns:ns="https://example.com/ns" attr="A & B "quoted""><ns:node><unescaped-tag> & symbol</ns:node></ns:root>';
const doc = parser.parseFromString(xml, 'text/xml');
const serialized = serializer.serializeToString(doc);
assert.ok(serialized.includes('xmlns:ns="https://example.com/ns"'), 'Namespace definition should be preserved');
assert.ok(serialized.includes('attr="A & B "quoted""'), 'Attribute special characters should be escaped');
assert.ok(serialized.includes('<unescaped-tag> & symbol'), 'Text special characters should be escaped');
}
// Assertion 5: XMLSerializer correctly formats self-closing empty XML elements
{
const xml = '<root><empty/><item flag="true"/><nested><emptyLeaf/></nested></root>';
const doc = parser.parseFromString(xml, 'text/xml');
const serialized = serializer.serializeToString(doc);
assert.equal(serialized, xml, 'Empty elements should be serialized as self-closing tags');
}
原始种子者
匿名