Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xml2lua.toXml() : Duplicated XML tags is broken when converting from Lua to XML #87

Open
chrisaga opened this issue Dec 10, 2022 · 4 comments

Comments

@chrisaga
Copy link

Use case : create a lua table and convert it to XML with duplicated tags

based on xml2lua/example3.lua we could expect :

local tag = { tag1={ 1='A', 2='B' } }
print(xml2lua.toXml(tag, 'tag')

would give :

<tag>
    <tag1>A</tag1>
    <tag1>B</tag1>
</tag>

but it gives insead :

<tag>
    <tag1>
      <tag1>A</tag1>
      <tag1>B</tag1>
    </tag1>
</tag>

The easyest way to test it is to append the following line at the end of xml2lua/example3.lua (select the 3rd test by uncommenting line 18) :

print(xml2lua.toXml(handler.root.tag, 'tag'))
@nilzao
Copy link
Collaborator

nilzao commented Feb 2, 2023

I couldn't reproduce the behavior.

Use this lua table to achieve the xml result.

local xml2lua = require("xml2lua")
local tagtable = { tag = { tag1 = { [1] = 'A', [2] = 'B' } } }
print(xml2lua.toXml(tagtable))
<tag>
    <tag1>A</tag1>
    <tag1>B</tag1>
</tag>

@mbabloapifonica
Copy link

I have a similar bug:

local initstr = [[<grammar xmlns="http://www.w3.org/2001/06/grammar" xml:lang="pl-PL" version="1.0" root="transcribe">
    <meta name="model" content="default"/>
    <tag name="language000" content="pl-PL"/>
    <rule id="transcribe">
        <one-of>
            <item>item1</item>
            <item>item2</item>
        </one-of>
    </rule>
</grammar>]]

xmlParser:parse(initstr)
print(initstr)
print("===")
print(xml2lua.toXml(xmlHandler.root))

so I try to load xml and the convert it back to xml, the response I get is:

<grammar xmlns="http://www.w3.org/2001/06/grammar" xml:lang="pl-PL" version="1.0" root="transcribe">
    <meta name="model" content="default"/>
    <tag name="language000" content="pl-PL"/>
    <rule id="transcribe">
        <one-of>
            <item>item1</item>
            <item>item2</item>
        </one-of>
    </rule>
</grammar>
===
<grammar root="transcribe" xmlns="http://www.w3.org/2001/06/grammar" version="1.0" xml:lang="pl-PL">
        <rule id="transcribe">
            <one-of>
                <item>
                  <item>item1</item>
                  <item>item2</item>
                </item>
            </one-of>
        </rule>
          <meta content="default" name="model">

          </meta>
            <tag content="pl-PL" name="language000">

            </tag>
    </grammar>

as you see one-of part looks in a different way:

            <one-of>
                <item>
                  <item>item1</item>
                  <item>item2</item>
                </item>
            </one-of>

instead of this

        <one-of>
            <item>item1</item>
            <item>item2</item>
        </one-of>

@mbabloapifonica
Copy link

UPD: I found out this problem happening on v.1.5-2 (the latest version that is currently available on luarocks)
Everything is working correctly on v.1.5-1 version. I'm not sure about v.1.6-1 as it is not available yet (for today) in luarocks

@Crazyokd
Copy link
Collaborator

@mbabloapifonica
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants