[erlang-questions] XML diff

Wes James <>
Wed Feb 1 17:49:45 CET 2012


On Tue, Jan 31, 2012 at 2:45 PM, Roberto Ostinelli <> wrote:
> Dear list,
>
> I was wandering if there is some available work done in generating XML files
> diff, obviously in Erlang but this is a broader question.


Are you going to have trivial xml files so that a simple line
comparison would work?

-module(spxml).

-export([p/0]).

p() ->
    {ok,F1}=file:open("f1.xml",read),
    {ok,F2}=file:open("f2.xml",read),
    p2(F1,F2,1).

p2(F1,F2,Acc) ->
    F1_line=file:read_line(F1),
    F2_line=file:read_line(F2),
    case F1_line of
        eof -> [];
        _ ->
             {ok,Res1}=F1_line,
             {ok,Res2}=F2_line,
            case Res1 =:= Res2 of
                 true -> [{ok, same, Acc}|p2(F1,F2,Acc+1)];
                 false -> [{ok, diff, Acc}|p2(F1,F2,Acc+1)]
            end
    end.

If not you, working with some of these ideas might:

http://erlang.2086793.n4.nabble.com/Compare-XML-string-td2268027.html

Regarding read_line, its odd that it returns a tuple until eof is
reached.  Shouldn't it return {ok, eof}?

-wes



More information about the erlang-questions mailing list