[erlang-questions] xmerl with multiple items

Joe Williams joe@REDACTED
Mon Sep 22 15:54:45 CEST 2008


I am working on one of the xmerl examples found at 
http://blog.tornkvist.org/blog.yaws?id=1193209275268448 specifically,

##########
-module(xp).
-export([go/1]).
-include_lib("xmerl/include/xmerl.hrl").
-define(Val(X),
    (fun() ->
       [#xmlElement{name = N,
                    content = [#xmlText{value = V}|_]}] = X,
             {N,V} end)()).

go(File) ->
   {Xml, _} = xmerl_scan:file(File),
   [?Val(xmerl_xpath:string("//SKU", Xml)),
    ?Val(xmerl_xpath:string("//ItemName", Xml)),
    ?Val(xmerl_xpath:string("//CollectionNo", Xml)),
    ?Val(xmerl_xpath:string("//Pages", Xml))].
##########


The issue that I am having is if I add to the example XML file that the 
site provides. I am changing the following,


##########
<Export>

|  <Product>
    <SKU>403276</SKU>
    <ItemName>Trivet</ItemName>
    <CollectionNo>0</CollectionNo>
    <Pages>0</Pages>
  </Product>
</Export>
|##########


to

##########

<Export>
  <Product>
    <SKU>403276</SKU>
    <ItemName>Trivet</ItemName>
    <CollectionNo>0</CollectionNo>
    <Pages>0</Pages>
  </Product>
  <Product>
    <SKU>123412</SKU>
    <ItemName>Book</ItemName>
    <CollectionNo>1</CollectionNo>
    <Pages>2</Pages>
  </Product>
</Export>

##########


When I run it against the XML it complains of,

##########

3> xp:go("xp.xml").
** exception error: no match of right hand side value
                    [{xmlElement,'SKU','SKU',[],
<snip>

##########


What is the best way to fix this issue so I can have the code work for 
one to many items?

Thanks.
-joe



-- 
Name: Joseph A. Williams
Email: joe@REDACTED




More information about the erlang-questions mailing list