NaturalIntelligence / fast-xml-parser

Validate XML, Parse XML and Build XML rapidly without C/C++ based libraries and no callback.
https://naturalintelligence.github.io/fast-xml-parser/
MIT License
2.49k stars 302 forks source link

Unexpected results when I use `transformTagName` alongside `allowBooleanAttributes`. #523

Closed facorreg closed 1 year ago

facorreg commented 1 year ago

Description

Typescript: 4.9.4 fast-xml-parser: ^4.0.12 Unexpected results when I use `transformTagName` alongside `allowBooleanAttributes`. Additionally (but off-topic), `transformAttributeName`, although mentionned in the documentation, is not a valid `X2jOptions` property. ### Input

Code

import fxp from "fast-xml-parser";

const entry = `
  <entry>
    <ent_seq>1358280</ent_seq>
    <k_ele>
      <keb>食べる</keb>
      <ke_pri>ichi1</ke_pri>
      <ke_pri>news2</ke_pri>
      <ke_pri>nf25</ke_pri>
    </k_ele>
    <k_ele>
      <keb>喰べる</keb>
      <ke_inf>&iK;</ke_inf>
    </k_ele>
    <r_ele>
      <reb>たべる</reb>
      <re_pri>ichi1</re_pri>
      <re_pri>news2</re_pri>
      <re_pri>nf25</re_pri>
    </r_ele>
  </entry>
`;

const parser = new fxp.XMLParser({
  ignoreAttributes: false,
  removeNSPrefix: true,
  allowBooleanAttributes: true,
  attributesGroupName: "@_",
  attributeNamePrefix: "",
  transformTagName: (tagName) => tagName.toUpperCase(),
});

const parsed = parser.parse(entry);

console.log(JSON.stringify(parsed, null, 2));

Output

{
  "ENTRY": {
    "ENT_SEQ": {
      "#text": 1358280,
      "@_": {
        "ent_seq": true
      }
    },
    "K_ELE": [
      {
        "KEB": {
          "#text": "食べる",
          "@_": {
            "keb": true
          }
        },
        "KE_PRI": [
          {
            "#text": "ichi1",
            "@_": {
              "ke_pri": true
            }
          },
          {
            "#text": "news2",
            "@_": {
              "ke_pri": true
            }
          },
          {
            "#text": "nf25",
            "@_": {
              "ke_pri": true
            }
          }
        ],
        "@_": {
          "k_ele": true
        }
      },
      {
        "KEB": {
          "#text": "喰べる",
          "@_": {
            "keb": true
          }
        },
        "KE_INF": {
          "#text": "&iK;",
          "@_": {
            "ke_inf": true
          }
        },
        "@_": {
          "k_ele": true
        }
      }
    ],
    "R_ELE": {
      "REB": {
        "#text": "たべる",
        "@_": {
          "reb": true
        }
      },
      "RE_PRI": [
        {
          "#text": "ichi1",
          "@_": {
            "re_pri": true
          }
        },
        {
          "#text": "news2",
          "@_": {
            "re_pri": true
          }
        },
        {
          "#text": "nf25",
          "@_": {
            "re_pri": true
          }
        }
      ],
      "@_": {
        "r_ele": true
      }
    },
    "@_": {
      "entry": true
    }
  }
}

expected data


{
  "ENTRY": {
    "ENT_SEQ": 1358280,
    "K_ELE": [
      {
        "KEB": "食べる",
        "KE_PRI": [
          "ichi1",
          "news2",
          "nf25"
        ]
      },
      {
        "KEB": "喰べる",
        "KE_INF": "&iK;"
      }
    ],
    "R_ELE": {
      "REB": "たべる",
      "RE_PRI": [
        "ichi1",
        "news2",
        "nf25"
      ]
    }
  }
}

Would you like to work on this issue?

Bookmark this repository for further updates.

github-actions[bot] commented 1 year ago

I'm glad you find this repository helpful. I'll try to address your issue ASAP. You can watch the repo for new changes or star it.

amitguptagwl commented 1 year ago

Can you please highlight the issue area? So I need not to compare the both outputs to find the problem. I hope your issue is not about preserveOrder

amitguptagwl commented 1 year ago

any update? please reopen the issue is still exist