Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rmraya/typesxml
Open source XML library written in TypeScript
https://github.com/rmraya/typesxml
parser typescript xml
Last synced: about 8 hours ago
JSON representation
Open source XML library written in TypeScript
- Host: GitHub
- URL: https://github.com/rmraya/typesxml
- Owner: rmraya
- License: epl-1.0
- Created: 2022-01-15T17:32:42.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-02T19:23:33.000Z (4 months ago)
- Last Synced: 2024-11-06T22:50:19.037Z (13 days ago)
- Topics: parser, typescript, xml
- Language: TypeScript
- Homepage:
- Size: 206 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TypesXML
Open source XML library written in TypeScript
Implements a SAX parser that exposes these methods from the `ContentHandler` interface:
* initialize(): void;
* setCatalog(catalog: Catalog): void;
* startDocument(): void;
* endDocument(): void;
* xmlDeclaration(version: string, encoding: string, standalone: string): void;
* startElement(name: string, atts: Array\): void;
* endElement(name: string): void;
* internalSubset(declaration: string): void;
* characters(ch: string): void;
* ignorableWhitespace(ch: string): void;
* comment(ch: string): void;
* processingInstruction(target: string, data: string): void;
* startCDATA(): void;
* endCDATA(): void;
* startDTD(name: string, publicId: string, systemId: string): void;
* endDTD(): void;
* skippedEntity(name: string): void;Class `DOMBuilder` implements the `ContentHandler` interface and builds a DOM tree from an XML document.
## Features currently in development
* Parsing of DTDs and internal subsets from
## Limitations
* Validation not supported yet
* Default values for attributes are not set when parsing an element## On the Roadmap
* Support for XML Schemas
* Support for RelaxNG## Installation
```bash
npm install typesxml
```## Example
```TypeScript
import { ContentHandler } from "./ContentHandler";
import { DOMBuilder } from "./DOMBuilder";
import { SAXParser } from "./SAXParser";
import { XMLDocument } from "./XMLDocument";
import { XMLElement } from "./XMLElement";export class Test {
constructor() {
try {
let contentHandler: ContentHandler = new DOMBuilder();
let xmlParser = new SAXParser();
xmlParser.setContentHandler(contentHandler);// build the document from a file
xmlParser.parseFile("test.xml");
let doc: XMLDocument = (contentHandler as DOMBuilder).getDocument();
let root: XMLElement = doc.getRoot();
console.log(doc.toString());// build the document again, this time from a string
xmlParser.parseString(doc.toString());
let newDoc = (contentHandler as DOMBuilder).getDocument();
console.log(newDoc.toString());} catch (error: any) {
if (error instanceof Error) {
console.log(error.message);
} else {
console.log(error);
}
}
}
}new Test();
```