Commit | Line | Data |
---|---|---|
fb584150 SK |
1 | # API: |
2 | # XmlPath : string | |
3 | # XmlAttr : dict : [XmlPath, string] -> string | |
4 | # XmlPayload : string | |
5 | ||
6 | /^[\(\)]/ { | |
7 | update_node() | |
8 | next | |
9 | } | |
10 | ||
11 | /^A/ && $2 == "CDATA" { | |
12 | update_node_attributes() | |
13 | next | |
14 | } | |
15 | ||
16 | /^-/ { | |
17 | XmlPayload = substr($0, 2, length($0)) | |
18 | } | |
19 | ||
20 | function path_to_string(path, depth, p, i) { | |
21 | p = "" | |
22 | for (i = 1; i <= depth; i++) { | |
23 | p = p "/" path[i] | |
24 | } | |
25 | return p | |
26 | } | |
27 | ||
28 | function update_node( paren, name, key, val, path, attr) { | |
29 | paren = substr($1, 1, 1) | |
30 | name = substr($1, 2, length($1) - 1) | |
31 | if (paren == "(") { | |
32 | _depth++ | |
33 | _path[_depth] = name | |
34 | XmlPath = path_to_string(_path, _depth) | |
35 | for (key in _hxpipe_curr_attrs) { | |
36 | val = _hxpipe_curr_attrs[key] | |
37 | XmlAttr[XmlPath, key] = val | |
38 | } | |
39 | } else if (paren == ")") { | |
40 | delete _hxpipe_curr_attrs | |
41 | XmlPayload = "" | |
42 | for (key in XmlAttr) { | |
43 | split(key, k, SUBSEP) | |
44 | path = k[1] | |
45 | attr = k[2] | |
46 | if (path == XmlPath) delete XmlAttr[key] | |
47 | } | |
48 | _depth-- | |
49 | XmlPath = path_to_string(_path, _depth) | |
50 | } else { | |
51 | printf("ERROR in input line %d - not a parenthesis: \"%s\"\n", NR, paren) > "/dev/stderr" | |
52 | exit 1 | |
53 | } | |
54 | } | |
55 | ||
56 | function update_node_attributes( key, val, s) { | |
57 | key = substr($1, 2, length($1)) | |
58 | val = $0 | |
59 | s = " +" | |
60 | sub("^" $1 s $2 s, "", val) | |
61 | _hxpipe_curr_attrs[key] = val | |
62 | } |