xmerl

Ulf Wiger <>
Wed Jun 11 13:54:24 CEST 2003


On Wed, 11 Jun 2003, James Freddy wrote:

>i'm trying to use xmerl to output xml.  i think what i want
>is to use xmerl:simple/3 and i followed the example on how
>to pass in the callback however the output is not xml. is
>there a simple example somehwere that shows how to output
>XML using xmerl?


Could you provide a little bit more detail about what you
did and what the output was?

I tried test:foo2() in xmerl-0.18, and it was broken.

I then tried the following. Apart from a missing line break
in the exported data, it looks pretty much as intended.

/Uffe

1> xmerl_scan:file("../priv/testdata/simple.xml").
{{xmlElement,section,
             [],
             [],
             1,
             [{xmlAttribute,heading,[],1,[],[],[],[],"heading1"}],
             [{xmlText,[{section,1}],1,[],"\n  "},
              {xmlElement,'P',
                          [{section,1}],
                          [],
                          2,
                          [],
                          [{xmlText,[{'P',2},{section,1}],
                                    1,
                                    [],
                                    "This is a paragraph of text."}],
                          [],
                          'P',
                          [],
                          {xmlNamespace,[],[]}},
              {xmlText,[{section,1}],3,[],"\n  "},
              {xmlElement,section,
                          [{section,1}],
                          [],
                          4,
                          [{xmlAttribute,heading,[],1,[],[],[],[]|...}],
                          [{xmlText,[{section,4},{section,1}],1,[],"\n    "},
                           {xmlElement,
                               'P',
                               [{section|...},{...}],
                               [],
                               2|...},
                           {xmlText,[{section,4},{section|...}],3,[],"\n    "},
                           {xmlElement,table,[{...}|...],[]|...},
                           {xmlText,[{...}|...],5|...}],
                          [],
                          section,
                          [],
                          {xmlNamespace,[],[]}},
              {xmlText,[{section,1}],5,[],"\n"}],
             [],
             section,
             [],
             {xmlNamespace,[],[]}},
 "\n"}
2> xmerl:export(element(1,v(1)),xmerl_xml).
["<?xml version=\"1.0\"?>",
 [["<","section",[[" ","heading","=\"","heading1","\""]],">"],
  ["\n  ",
   [["<","P",">"],["This is a paragraph of text."],["</","P",">"]],
   "\n  ",
   [["<","section",[[" ","heading","=\"","heading2","\""]],">"],
    ["\n    ",
     [["<","P",">"],["This is another paragraph"],["</","P",">"]],
     "\n    ",
     [["<","table",[[" ","border","=\"","1","\""]],">"],
      ["\n       ",
       [["<","heading",">"],
        ["\n         ",
         [["<","col",">"],["head1"],["</","col",">"]],
         "\n         ",
         [["<","col",">"],["head2"],["</","col"|...]],
         "\n       "],
        ["</","heading",">"]],
       "\n       ",
       [["<","row",">"],
        ["\n         ",
         [["<","col",">"],["col11"],["</","col"|...]],
         "\n         ",
         [["<","col"|...],["col12"],[...]],
         "\n       "],
        ["</","row",">"]],
       "\n       ",
       [["<","row",">"],
        ["\n         ",
         [["<","col"|...],["col21"],[...]],
         "\n         ",
         [[...]|...],
         "\n       "],
        ["</","row",">"]],
       "\n    "],
      ["</","table",">"]],
     "\n  "],
    ["</","section",">"]],
   "\n"],
  ["</","section",">"]]]
3> io:format("~s~n", [v(2)]).
<?xml version="1.0"?><section heading="heading1">
  <P>This is a paragraph of text.</P>
  <section heading="heading2">
    <P>This is another paragraph</P>
    <table border="1">
       <heading>
         <col>head1</col>
         <col>head2</col>
       </heading>
       <row>
         <col>col11</col>
         <col>col12</col>
       </row>
       <row>
         <col>col21</col>
         <col>col22</col>
       </row>
    </table>
  </section>
</section>
ok
5> {ok,B} =
file:read_file("../priv/testdata/simple.xml"),io:format("~s~n",
[binary_to_list(B)]).
<section heading="heading1">
  <P>This is a paragraph of text.</P>
  <section heading="heading2">
    <P>This is another paragraph</P>
    <table border="1">
       <heading>
         <col>head1</col>
         <col>head2</col>
       </heading>
       <row>
         <col>col11</col>
         <col>col12</col>
       </row>
       <row>
         <col>col21</col>
         <col>col22</col>
       </row>
    </table>
  </section>
</section>

ok

-- 
Ulf Wiger, Senior Specialist,
   / / /   Architecture & Design of Carrier-Class Software
  / / /    Strategic Product & System Management
 / / /     Ericsson AB, Connectivity and Control Nodes




More information about the erlang-questions mailing list