https://github.com/mmaltsev/xml2tree
Visualize XML data as a tree.
https://github.com/mmaltsev/xml2tree
d3 tree xml
Last synced: 11 months ago
JSON representation
Visualize XML data as a tree.
- Host: GitHub
- URL: https://github.com/mmaltsev/xml2tree
- Owner: mmaltsev
- License: mit
- Created: 2017-05-21T12:11:15.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-05-20T12:56:13.000Z (about 7 years ago)
- Last Synced: 2025-07-31T06:37:55.250Z (11 months ago)
- Topics: d3, tree, xml
- Language: JavaScript
- Homepage: https://mmaltsev.github.io/Xml2Tree/
- Size: 325 KB
- Stars: 18
- Watchers: 1
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [Xml2Tree](https://github.com/mmaltsev/XML2Tree)
Xml2Tree is a library for visualizing XML data in the browser as a tree using d3.js.
Demo: https://mmaltsev.github.io/Xml2Tree/
Docs: https://mmaltsev.github.io/Xml2Tree/docs/
## Install
#### Add link to the library:
```html
```
#### Create new div element:
```html
```
#### Call function:
```html
xmltotree("chart1", "example/example.xml", [], false, false)
```
## Options
| Variable | Type | Description |
| ----------------- | ------- | ---------------------- |
| elementId | string | id of div that contains tree. |
| filePath | string | Path to the XML file. |
| secondLevelNodes | array of strings | List of nodes to show on second level of tree. Other will be contained in 'Extra'. If not specified - everything is shown. |
| isAttributes | boolean | Whether to show all attributes of elements in XML or not. |
| isJSON | boolean | Specified when input file is JSON. |
## Examples
You can find an XML file that is used below [here](example/example.xml).
#### 1 Example Code:
```html
var elementId = 'chart1';
var filePath = 'example/example.xml';
var secondLevelNodes = [];
var isAttributes = true;
var isJSON = false;
xml2tree(elementId, filePath, secondLevelNodes, isAttributes, isJSON);
```
#### 1 Example Result:

#### 2 Example Code:
```html
var elementId = 'chart1';
var filePath = 'example/example.xml';
var secondLevelNodes = ['book'];
var isAttributes = false;
var isJSON = false;
xml2tree(elementId, filePath, secondLevelNodes, isAttributes, isJSON);
```
#### 2 Example Result:

## License.
MIT License. Copyright (c) 2016-2017 Maxim Maltsev.