Skip to content

Instantly share code, notes, and snippets.

@omarkj
Created September 25, 2012 11:25
Show Gist options
  • Save omarkj/3781219 to your computer and use it in GitHub Desktop.
Save omarkj/3781219 to your computer and use it in GitHub Desktop.

XML

<tag-definition>
        <name>NumberOfTrades</name>
          
          
          <value>q</value>
          <type length="10">Integer</type>
      </tag-definition>

      <tag-definition>
        <name>ReportedVolume</name>
          
          
          <value>Rq</value>
          <type length="16" decimals="6">Float</type>
      </tag-definition>

Erlang

hook(#xmlElement{name='tag-definition',
		 content=Content}=TagDef, GlobalState) ->
    Tag0 = parse_tag(Content, #tag{}),
    mnesia:transaction(fun() -> ok = mnesia:write(Tag0) end),
    {[], GlobalState};

Parsed XML

When type has the decimals attribute:

{xmlElement,'tag-definition','tag-definition',[],
              {xmlNamespace,[],[]},
              [{'tag-definitions',5},{tip,1}],
              31,[],
              [{xmlElement,name,name,[],
                   {xmlNamespace,[],[]},
                   [{'tag-definition',31},{'tag-definitions',5},{tip,1}],
                   1,[],
                   [{xmlText,
                        [{name,1},
                         {'tag-definition',31},
                         {'tag-definitions',5},
                         {tip,1}],
                        1,[],"ReportedVolume",text}],
                   [],undefined,undeclared},
               {xmlElement,value,value,[],
                   {xmlNamespace,[],[]},
                   [{'tag-definition',31},{'tag-definitions',5},{tip,1}],
                   2,[],
                   [{xmlText,
                        [{value,2},
                         {'tag-definition',31},
                         {'tag-definitions',5},
                         {tip,1}],
                        1,[],"Rq",text}],
                   [],undefined,undeclared},
               {xmlElement,type,type,[],
                   {xmlNamespace,[],[]},
                   [{'tag-definition',31},{'tag-definitions',5},{tip,1}],
                   3,
                   [{xmlAttribute,length,[],[],[],
                        [{type,3},
                         {'tag-definition',31},
                         {'tag-definitions',5},
                         {tip,1}],
                        1,[],"16",false},
                    {xmlAttribute,decimals,[],[],[],
                        [{type,3},
                         {'tag-definition',31},
                         {'tag-definitions',5},
                         {tip,1}],
                        2,[],"6",false}],
                   [{xmlText,
                        [{type,3},
                         {'tag-definition',31},
                         {'tag-definitions',5},
                         {tip,1}],
                        1,[],"Float",text}],
                   [],undefined,undeclared}],
              [],undefined,undeclared}

When it doesn't have Decimals:

TagDef is {xmlElement,'tag-definition','tag-definition',[],
              {xmlNamespace,[],[]},
              [{'tag-definitions',5},{tip,1}],
              30,[],
              [{xmlElement,name,name,[],
                   {xmlNamespace,[],[]},
                   [{'tag-definition',30},{'tag-definitions',5},{tip,1}],
                   1,[],
                   [{xmlText,
                        [{name,1},
                         {'tag-definition',30},
                         {'tag-definitions',5},
                         {tip,1}],
                        1,[],"NumberOfTrades",text}],
                   [],undefined,undeclared},
               {xmlElement,value,value,[],
                   {xmlNamespace,[],[]},
                   [{'tag-definition',30},{'tag-definitions',5},{tip,1}],
                   2,[],
                   [{xmlText,
                        [{value,2},
                         {'tag-definition',30},
                         {'tag-definitions',5},
                         {tip,1}],
                        1,[],"q",text}],
                   [],undefined,undeclared},
               []],
              [],undefined,undeclared}

The type is missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment