https://github.com/samchon/sxml
Simple XML Library for TypeScript (JavaScript)
https://github.com/samchon/sxml
Last synced: 11 months ago
JSON representation
Simple XML Library for TypeScript (JavaScript)
- Host: GitHub
- URL: https://github.com/samchon/sxml
- Owner: samchon
- License: mit
- Created: 2018-01-31T03:29:53.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2025-02-16T19:24:50.000Z (over 1 year ago)
- Last Synced: 2025-07-21T21:24:20.789Z (11 months ago)
- Language: TypeScript
- Homepage:
- Size: 41 KB
- Stars: 18
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple XML
[](https://github.com/samchon/sxml/blob/master/LICENSE)
[](https://www.npmjs.com/package/sxml)
[](https://www.npmjs.com/package/sxml)
[](https://github.com/samchon/sxml/actions?query=workflow%3Abuild)
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fsamchon%2Fsxml?ref=badge_shield)
[](https://gitter.im/samchon/sxml?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
It's the most simple, concise and eledic library for XML. Just remember that structure, then you'll understand how to use it. If you want to know more about the detailed features, then utilize auto-completion of TypeScript or read the [Guide Documents](https://github.com/samchon/sxml/wiki).
```typescript
declare module "sxml"
{
export class XML extends std.HashMap
{
private tag_: string;
private value_: string;
private property_map_: std.HashMap;
}
export class XMLList extends std.Vector;
}
```
## Installation
### NPM Module
Installing **SXML** in *NodeJS* is very easy. Just install with the `npm`
```bash
# Install SXML from the NPM module
npm install --save sxml
```
### Usage
In this section, we will study how to parse XML-string and access to members of that XML object. It's very simple and easy. Just remember and consider the principle structure of this `SXML`.
If you want to know more about the detailed features or how to generate XML, then utilize auto-completion of TypeScript or read the [Guide Documents](https://github.com/samchon/sxml/wiki).
#### example.xml
```xml
simulation
3
```
#### read.ts
```typescript
import fs = require("fs");
import sxml = require("sxml");
import XML = sxml.XML;
import XMLList = sxml.XMLList;
function main(): void
{
let str: string = fs.readFileSync("example.xml", "utf8");
trace(str);
}
function trace(str: string): void
{
// CREATE AN XML OBJECT BY PARSING CHARACTERS
let xml: XML = new XML(str);
//----
// LIST OF PARAMETER OBJECTS
//----
// XML => std.HashMap
// XMLList => std.Vector
let xmlList: XMLList = xml.get("parameter");
console.log("#" + xmlList.size()); // #3
// PROPERTIES & VALUE OF 1ST PARAMETER
console.log
(
xmlList.at(0).getProperty("name"), // "application"
xmlList.at(0).getProperty("type"), // "string"
xmlList.at(0).getValue() // "simulation"
);
// PROPERTIES & VALUE OF 2ND PARAMETER
console.log
(
xmlList.at(1).getProperty("name"), // "sequence"
xmlList.at(1).getProperty("type"), // "number"
xmlList.at(1).getValue() // "3"
);
//----
// ACCESS TO CHILDREN XML OBJECTS
//----
let members: XMLList = xml.get("parameter").at(2)
.get("memberList").at(0)
.get("member");
// PRINT PROPERTIES
console.log
(
members.at(0).getProperty("id"), // "samchon"
members.at(1).getProperty("email"), // "github@github.com"
members.at(2).getProperty("name") // "Alphago
);
}
main();
```
## References
- **Repositories**
- [GitHub Repository](https://github.com/samchon/sxml)
- [NPM Repository](https://www.npmjs.com/package/sxml)
- **Documents**
- [**Guide Documents**](https://github.com/samchon/sxml/wiki)
- [API Documents](http://samchon.github.io/sxml/api)
- **Related Project**
- [TSTL](https://github.com/samchon/tstl)