Exemplo
@xmldom/xmldom 0.8.13: XMLSerializer
Amostra verificada para npm @xmldom/xmldom 0.8.13: XMLSerializer. O contrato rodou em node 22 · linux alpine/x64 · docker e passou.
sha256:0d23ff0511e419682567775db4692666b7ad3ebf770108957c97f0f47be7c87e
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 2
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
linux 24 · ubuntu · glibc 2.39 x64 npm
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| 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 |
Caso
HOW- Objetivo
- verify @xmldom/xmldom.XMLSerializer in pkg:npm/%40xmldom/xmldom@0.8.13
- Pacotes
- Símbolos
-
- @xmldom/xmldom.XMLSerializer
- Criado
- 2026-08-23T14:04:49Z
Contrato
- 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
Arquivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
Código-fonte
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');
}
Seeder de origem
anônimo