Skip to content

Commit a75bcb3

Browse files
committed
domxpath doc
1 parent 299a739 commit a75bcb3

File tree

3 files changed

+67
-64
lines changed

3 files changed

+67
-64
lines changed

docs/make.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ makedocs(;
1313
),
1414
pages=[
1515
"Home" => "index.md",
16-
17-
"Value Checking" => "valueChecking.md",
1816
"Supported Value Types" => "supportedValueTypes.md",
17+
"Value Checking" => "valueChecking.md",
1918
"Extra Contructors" => "extraConstructors.md",
20-
2119
"Custom Value Types" => "customValueTypes.md",
22-
"Custom Contructors - AcuteML Backend" => "customConstructors.md",
23-
20+
"Custom Contructors" => "customConstructors.md",
21+
"DOM/XPath API" => "domxpath.md",
2422
"Templating" => "templating.md",
2523
"Syntax Reference" => "SyntaxReference.md"
2624
],

docs/src/customConstructors.md

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -110,62 +110,3 @@ mathclass = MathClass(xml)
110110

111111
mathclass.students[2].log # "A genius with a GPA of 5.0 is found"
112112
```
113-
114-
## Making a Type and constructor from scratch using AcuteML Backend
115-
116-
You can use AcuteML utilities to define custom type constructors from scratch or to override `@aml` defined constructors.
117-
118-
Notice that if you don't use `@aml`, you should include `aml::Node` as one of your fields.
119-
120-
Functions to use for custom html/xml constructor:
121-
- [initialize_node](@ref): function to initialize the aml
122-
- [addelm!](@ref) : to add elements (single or a vector of elements)
123-
Use these functions, to make a method that calculates the `aml` inside the function and returns all of the fields.
124-
125-
Functions to use for custom html/xml extractor:
126-
- [findcontent](@ref) : to extract elements
127-
Use these functions, to make a method that gets the `aml::Node` and calculates and returns all of the fields.
128-
129-
Functions to support mutability:
130-
- [updatecontent!](@ref): Finds all the elements with the address of string in the node, and updates the content.
131-
132-
# Example:
133-
In this example we define `Identity` with custom constructors:
134-
```julia
135-
using AcuteML
136-
137-
mutable struct Identity
138-
pitch::UN{Pitch}
139-
rest::UN{Rest}
140-
unpitched::UN{Unpitched}
141-
aml::Node
142-
end
143-
144-
function Identity(;pitch = nothing, rest = nothing, unpitched = nothing)
145-
146-
# This constructor only allows one the fields to exist - similar to choice element in XS
147-
148-
aml = initialize_node(AbsNormal, "identity")
149-
150-
if pitch != nothing
151-
addelm!(aml, "pitch", pitch, AbsNormal)
152-
elseif rest != nothing
153-
addelm!(aml, "rest", rest, AbsNormal)
154-
elseif unpitched != nothing
155-
addelm!(aml, "unpitched", unpitched, AbsNormal)
156-
else
157-
error("one of the pitch, rest or unpitched should be given")
158-
end
159-
160-
return Identity(pitch, rest, unpitched, aml)
161-
end
162-
163-
function Identity(;aml)
164-
165-
pitch = findcontent(Pitch, "pitch", aml, AbsNormal)
166-
rest = findcontent(Rest, "rest", aml, AbsNormal)
167-
unpitched = findcontent(Unpitched, "unpitched", aml, AbsNormal)
168-
169-
return Identity(pitch, rest, unpitched, aml)
170-
end
171-
```

docs/src/domxpath.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# AcuteML DOM/Xpath API
2+
3+
AcuteML provides a DOM/Xpath API that you can use to do lower level XML/HTML manipulation if needed.
4+
5+
You can use AcuteML utilities to define custom type constructors from scratch or to override `@aml` defined constructors.
6+
7+
Notice that if you don't use `@aml`, you should include `aml::Node` as one of your fields.
8+
9+
Functions to use for custom html/xml constructor:
10+
- [createnode](@ref): function to create a node/document
11+
- [addnode!](@ref) : To add nodes (single or a vector of nodes) as a child of given a node/document.
12+
Use these functions, to make a method that calculates the `aml` inside the function and returns all of the fields.
13+
14+
Functions to use for custom html/xml extractor:
15+
- [findfirst](@ref): to find the first node based on the given node name
16+
- [findall](@ref): to find all of the nodes based on the given node name
17+
- [findcontent](@ref) : to get the content of a node based on the given name
18+
Use these functions, to make a method that gets the `aml::Node` and calculates and returns all of the fields.
19+
20+
Functions to support mutability:
21+
- [updatecontent!](@ref): Finds all the elements with the address of string in the node, and updates the content.
22+
23+
## Making a Type and constructor from scratch using AcuteML Backend
24+
25+
# Example:
26+
In this example we define `Identity` with custom constructors:
27+
```julia
28+
using AcuteML
29+
30+
mutable struct Identity
31+
pitch::UN{Pitch}
32+
rest::UN{Rest}
33+
unpitched::UN{Unpitched}
34+
aml::Node
35+
end
36+
37+
function Identity(;pitch = nothing, rest = nothing, unpitched = nothing)
38+
39+
# This constructor only allows one the fields to exist - similar to choice element in XS
40+
41+
aml = createnode(AbsNormal, "identity")
42+
43+
if pitch != nothing
44+
addnode!(aml, "pitch", pitch, AbsNormal)
45+
elseif rest != nothing
46+
addnode!(aml, "rest", rest, AbsNormal)
47+
elseif unpitched != nothing
48+
addnode!(aml, "unpitched", unpitched, AbsNormal)
49+
else
50+
error("one of the pitch, rest or unpitched should be given")
51+
end
52+
53+
return Identity(pitch, rest, unpitched, aml)
54+
end
55+
56+
function Identity(;aml)
57+
58+
pitch = findcontent(Pitch, "pitch", aml, AbsNormal)
59+
rest = findcontent(Rest, "rest", aml, AbsNormal)
60+
unpitched = findcontent(Unpitched, "unpitched", aml, AbsNormal)
61+
62+
return Identity(pitch, rest, unpitched, aml)
63+
end
64+
```

0 commit comments

Comments
 (0)