diff options
Diffstat (limited to 'src/xml.erl')
-rw-r--r-- | src/xml.erl | 103 |
1 files changed, 67 insertions, 36 deletions
diff --git a/src/xml.erl b/src/xml.erl index e14f54c15..222e49b3e 100644 --- a/src/xml.erl +++ b/src/xml.erl @@ -20,26 +20,26 @@ get_path_s/2, replace_tag_attr/3]). -element_to_string(El) -> - case El of - {xmlelement, Name, Attrs, Els} -> - if length(Els) > 0 -> - "<" ++ Name ++ attrs_to_string(Attrs) ++ ">" ++ - lists:append( - lists:map(fun(E) -> element_to_string(E) end, Els)) - ++ "</" ++ Name ++ ">"; - true -> - "<" ++ Name ++ attrs_to_string(Attrs) ++ "/>" - end; - {xmlcdata, CData} -> crypt(CData) - end. - - -attrs_to_string(Attrs) -> - lists:append(lists:map(fun(A) -> attr_to_string(A) end, Attrs)). - -attr_to_string({Name, Value}) -> - " " ++ crypt(Name) ++ "='" ++ crypt(Value) ++ "'". +%element_to_string(El) -> +% case El of +% {xmlelement, Name, Attrs, Els} -> +% if length(Els) > 0 -> +% "<" ++ Name ++ attrs_to_string(Attrs) ++ ">" ++ +% lists:append( +% lists:map(fun(E) -> element_to_string(E) end, Els)) +% ++ "</" ++ Name ++ ">"; +% true -> +% "<" ++ Name ++ attrs_to_string(Attrs) ++ "/>" +% end; +% {xmlcdata, CData} -> crypt(CData) +% end. +% +% +%attrs_to_string(Attrs) -> +% lists:append(lists:map(fun(A) -> attr_to_string(A) end, Attrs)). +% +%attr_to_string({Name, Value}) -> +% " " ++ crypt(Name) ++ "='" ++ crypt(Value) ++ "'". %element_to_string2(El) -> @@ -64,25 +64,56 @@ attr_to_string({Name, Value}) -> %attr_to_list({Name, Value}) -> % [" ", crypt(Name), "='", crypt(Value), "'"]. +element_to_string(El) -> + case El of + {xmlelement, Name, Attrs, Els} -> + if + Els /= [] -> + [$<, Name, attrs_to_list(Attrs), $>, + [element_to_string(E) || E <- Els], + $<, $/, Name, $>]; + true -> + [$<, Name, attrs_to_list(Attrs), $/, $>] + end; + {xmlcdata, CData} -> + crypt(CData) + end. + +attrs_to_list(Attrs) -> + [attr_to_list(A) || A <- Attrs]. + +attr_to_list({Name, Value}) -> + [$\s, crypt(Name), $=, $', crypt(Value), $']. + +%crypt(S) -> +% lists:reverse(crypt(S, "")). +% +%crypt([$& | S], R) -> +% crypt(S, [$;, $p, $m, $a, $& | R]); +%crypt([$< | S], R) -> +% crypt(S, [$;, $t, $l, $& | R]); +%crypt([$> | S], R) -> +% crypt(S, [$;, $t, $g, $& | R]); +%crypt([$" | S], R) -> +% crypt(S, [$;, $t, $o, $u, $q, $& | R]); +%crypt([$' | S], R) -> +% crypt(S, [$;, $s, $o, $p, $a, $& | R]); +%crypt([C | S], R) -> +% crypt(S, [C | R]); +%crypt([], R) -> +% R. + crypt(S) -> - lists:reverse(crypt(S, "")). - -crypt([$& | S], R) -> - crypt(S, [$;, $p, $m, $a, $& | R]); -crypt([$< | S], R) -> - crypt(S, [$;, $t, $l, $& | R]); -crypt([$> | S], R) -> - crypt(S, [$;, $t, $g, $& | R]); -crypt([$" | S], R) -> - crypt(S, [$;, $t, $o, $u, $q, $& | R]); -crypt([$' | S], R) -> - crypt(S, [$;, $s, $o, $p, $a, $& | R]); -crypt([C | S], R) -> - crypt(S, [C | R]); -crypt([], R) -> - R. + [case C of + $& -> "&"; + $< -> "<"; + $> -> ">"; + $" -> """; + $' -> "'"; + _ -> C + end || C <- S]. %crypt1(S) -> % lists:flatten([case C of |