Skip to content

Commit f8648dd

Browse files
committed
readme, export simplevalue and is_simple
1 parent 8e71456 commit f8648dd

File tree

2 files changed

+37
-36
lines changed

2 files changed

+37
-36
lines changed

README.md

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,28 @@
44

55
<br><br>
66

7-
## Introduction
7+
# Introduction
88

99
This package offers fast data structures for reading and writing XML files with a consistent interface:
1010

11-
#### `Node`/`LazyNode` Interface:
11+
### `Node`/`LazyNode` Interface:
1212

13-
- `nodetype(node) → XML.NodeType` (an enum with one of the following values):
14-
- `Document`: `children...`
15-
- `DTD`: `<!DOCTYPE ...>`
16-
- `Declaration`: `<?xml attributes... ?>`
17-
- `ProcessingInstruction`: `<?NAME attributes... ?>`
18-
- `Comment`: `<!-- ... -->`
19-
- `CData`: `<![CData[...]]>`
20-
- `Element`: `<NAME attributes... > children... </NAME>`
21-
- `Text`: `text`
22-
- `tag(node) → String or Nothing`
23-
- `attributes(node) → Dict{String,String} or Nothing`
24-
- `value(node) → String or Nothing`
25-
- `children(node) → Vector{typeof(node)}`
13+
- `nodetype(node) → XML.NodeType` (an enum type):
14+
- `tag(node) → String or Nothing`
15+
- `attributes(node) → Dict{String,String} or Nothing`
16+
- `value(node) → String or Nothing`
17+
- `children(node) → Vector{typeof(node)}`
18+
- `is_simple(node) → Bool (whether node is simple .e.g. <tag>item</tag>)`
19+
- `simplevalue(node) → Return the `value` of the only child (e.g. "item" from <tag>item</tag>)`
2620

27-
#### Extended Interface for `LazyNode`
21+
### Extended Interface for `LazyNode`
2822

2923
- `depth(node) → Int`
3024
- `next(node) → typeof(node)`
3125
- `prev(node) → typeof(node)`
3226
- `parent(node) → typeof(node)`
3327

34-
## Quickstart
28+
# Quickstart
3529

3630
```julia
3731
using XML
@@ -52,41 +46,47 @@ doc[end][2] # Second child of root
5246
# Node Element <book id="bk102"> (6 children)
5347
```
5448

55-
## Node Types
49+
# Data Structures that Represent XML Nodes
5650

57-
### `XML.Node`
51+
## Preliminary: `NodeType`
5852

59-
- An eager data structure that loads the entire XML DOM in memory.
53+
- Each item in an XML DOM is classified by its `NodeType`.
54+
- Every `XML.jl` struct defines a `nodetype(x)` method that returns its `NodeType`.
55+
56+
| NodeType | XML Representation | `Node` Constructor |
57+
|----------|--------------------|------------------|
58+
| `Document` | An entire document | `Document(children...)`
59+
| `DTD` | `<!DOCTYPE ...>` | `DTD(...) `
60+
| `Declaration` | `<?xml attributes... ?>` | `Declaration(; attrs...)`
61+
| `ProcessingInstruction` | `<?tag attributes... ?>` | `ProcessingInstruction(tag; attrs...)`
62+
| `Comment` | `<!-- text -->` | `Comment(text)`
63+
| `CData` | `<![CData[text]]>` | `CData(text)`
64+
| `Element` | `<tag attributes... > children... </NAME>` | `Element(tag, children...; attrs...)`
65+
| `Text` | the `text` part of `<tag>text</tag>` | `Text(text)`
66+
67+
68+
## `Node`: Probably What You're Looking For
69+
70+
- `read`-ing a `Node` loads the entire XML DOM in memory.
6071
- **This is what you would use to build an XML document programmatically.**
72+
- See the table above for convenience constructors.
6173
- `Node`s have some additional methods that aid in construction/mutation:
6274

6375
```julia
6476
# Add a child:
6577
push!(parent::Node, child::Node)
6678

67-
6879
# Replace a child:
6980
parent[2] = child
7081

71-
7282
# Add/change an attribute:
7383
node["key"] = value
74-
```
75-
76-
- **XML** defines `(::NodeType)(args...; kw...)` for more convenient syntax in creating `Node`s, e.g.:
7784

78-
```julia
79-
CData(value)
80-
Comment(value)
81-
Declaration(; attributes...)
82-
Document(children...)
83-
DTD(; attributes...)
84-
Element(tag, children...; attributes...)
85-
ProcessingInstruction(tag; attributes...)
86-
Text(value)
85+
node["key"]
8786
```
8887

89-
### `XML.LazyNode`
88+
89+
## `XML.LazyNode`: For Fast Iteration through an XML File
9090

9191
A lazy data structure that just keeps track of the position in the raw data (`Vector{UInt8}`) to read from.
9292

@@ -134,6 +134,7 @@ XML.write(node) # String
134134

135135
## Performance
136136

137+
- XML.jl performs comparatively to [EzXML.jl](https://github.com/JuliaIO/EzXML.jl), which wraps the C library [libxml2](https://gitlab.gnome.org/GNOME/libxml2/-/wikis/home).
137138
- See the `benchmarks/suite.jl` for the code to produce these results.
138139
- The following output was generated in a Julia session with the following `versioninfo`:
139140

src/XML.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export
66
# Core Types:
77
Node, LazyNode,
88
# Interface:
9-
children, nodetype, tag, attributes, value,
9+
children, nodetype, tag, attributes, value, is_simple, simplevalue,
1010
# Extended Interface for LazyNode:
1111
parent, depth, next, prev
1212

0 commit comments

Comments
 (0)