一覧へ戻る
DreamLoom-AI/xml-ez(新しいタブで開きます)
主要言語: TypeScript
A TypeScript library for easy conversion between Zod schemas and XML/XSD.
- star 数
- 11
- watcher 数
- 0
- fork 数
- 1
- issue 数
- 0
- 最終更新
- 2024/12/09
主要言語: TypeScript
A TypeScript library for easy conversion between Zod schemas and XML/XSD.
A TypeScript library for easy conversion between Zod schemas and XML/XSD. This library provides utilities to convert Zod schemas to XML Schema Definition (XSD) and parse XML documents into JavaScript objects.
npm install xml-ez
import { z } from 'zod'; import { zodToXmlSchema } from 'xml-ez'; // Define your Zod schema const userSchema = z.object({ name: z.string().describe('User\'s full name'), age: z.number().describe('User\'s age'), hobbies: z.array(z.string()).describe('List of hobbies') }); // Convert to XSD const xsd = zodToXmlSchema(userSchema, 'User'); console.log(xsd);
import { parseXmlToObject } from 'xml-ez'; const xmlString = ` <?xml version="1.0" encoding="UTF-8"?> <User> <name>John Doe</name> <age>30</age> <hobbies> <hobby>Reading</hobby> <hobby>Gaming</hobby> </hobbies> </User> `; const result = parseXmlToObject(xmlString); console.log(result); // Output: { name: 'John Doe', age: 30, hobbies: ['Reading', 'Gaming'] }
Converts a Zod schema to XML Schema (XSD).
zodSchema: The Zod schema to convertrootName: Optional name for the root element (defaults to 'Root')Parses an XML string into a JavaScript object.
xmlString: The XML string to parseMIT