BUG? expanding xml content...

Ulf Wiger ulf.wiger@REDACTED
Mon Oct 25 15:47:58 CEST 2010


While debugging the edown component, I started noticing 
a weird thing about how XMERL expands content.

The function is mainly called upon to expand 'simple' content,
and does this well, but EDoc passes in a mix of simple content and 
xmerl records.

First, the correct expansion of simple content:

9> xmerl_lib:expand_content([{a,[{b,[{c,[]}]}]}]).
[#xmlElement{
     name = a,...
     parents = [],...
     content = [
         #xmlElement{
             name = b,...
             parents = [{a,1}],
             content = [
                 #xmlElement{
                     name = c,...
                     parents = [{b,1},{a,1}],...}]

The thing to note is how the 'parents' attribute is faithfully maintained.

Now, the same call with manually created records:

1> xmerl_lib:expand_content(
  [#xmlElement{
       name=a,
       content=
          [#xmlElement{
              name=b,
              content=[
                 #xmlElement{name=c}]}]}]).
[#xmlElement{
     name = a,...
     parents = [],...
     content = [
         #xmlElement{
             name = b,...
             parents = [],...
             content = [
                 #xmlElement{name = c,...
                             parents = [],...}],
             ...}]

The problem is that when it encounters xmerl records, it simply 
assumes that the parent attribute is correct, but in the case of 
manually constructed xmerl trees, it most likely isn't.

Also, if the structures are transplanted from a parsed document,
chances are that the 'parents' attribute is still wrong in the new context.

Unless someone comes up with a strong defense in favour of the existing
semantics, I will work on a patch that makes expand_content always 
update the 'parents' attribute.

(Since the xmerl test suites are not yet available, that patch would unfortunately
not contain updated tests. If someone on the OTP team feels like just fixing this,
as it is a pretty simple change, please let me know.)

BR,
Ulf W

Ulf Wiger, CTO, Erlang Solutions, Ltd.
http://erlang-solutions.com





More information about the erlang-questions mailing list