Last active
January 21, 2019 01:33
-
-
Save refactor/21926e2b9dda1857ef7e6b55b2389142 to your computer and use it in GitHub Desktop.
try to modify xml, add some element node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-include_lib("xmerl/include/xmerl.hrl"). | |
%% tuple -> xml-erl | |
TL = {filemeta,[{id,'/Foo'},{bar,12111111113}], [{name,["11"]},{age,["1"]}]}. | |
XmlDoc = xmerl:export_simple([TL], xmerl_xml). | |
%% xml-erl -> tuple | |
TL = xmerl_lib:simplify_element(XmlDoc). | |
% xml-file -> tuple | |
{XmlDoc,_} = xmerl_scan:file("my-dem.vrt"). | |
TL = xmerl_lib:simplify_element(XmlDoc). | |
% xml-string -> tuple | |
{XmlDoc, _} = xmerl_scan:string(Str). | |
TL = xmerl_lib:simplify_element(XmlDoc). | |
% parse xml node... but it's complex, I'd rather parsing tuple | |
%% shell> rr(code:lib_dir(xmerl) ++ "/include/xmerl.hrl"). | |
XmlDoc#xmlElement.content. | |
NewTL = work_on(TL). | |
% tuple -> xml-string | |
lists:flatten(xmerl:export_simple([NewTL], xmerl_xml))). | |
% tuple -> xml-string | |
% rm header: "<?xml version=\"1.0\"?>" | |
lists:flatten(tl(xmerl:export_simple([NewTL], xmerl_xml))). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment