manoelcampos / xml2lua

XML Parser written entirely in Lua that works for Lua 5.1+. Convert XML to and from Lua Tables 🌖💱
MIT License
289 stars 74 forks source link

Manipulating an existing XML document #38

Closed latenitefilms closed 4 years ago

latenitefilms commented 4 years ago

First up, thanks @manoelcampos for creating such an awesome Lua extension - very much appreciated!

I'm currently investigating a way to import an existing XML document a (FCPXML document from Apple's Final Cut Pro), manipulate it in Lua-land, then export out a new document.

For now though, I'm having issues making the output match the input.

Here's the example XML document I'm using.

Here's the basic test code I'm using:

local xml2lua = require("xml2lua.xml2lua")
local handler = require("xml2lua.xmlhandler.tree")
local xml = xml2lua.loadFile("/Users/chrishocking/Desktop/Test Project.fcpxml")
local parser = xml2lua.parser(handler)
parser:parse(xml)
print(xml2lua.toXml(handler.root.fcpxml, "fcpxml"))

Here's the output:

<fcpxml>
<fcpxml>
  <library>
<3>
<event>
<2>
<project>
<2>
<_attr>
<2>
<name>Test Project</name>
<uid>1CE43CBF-B3AC-4AB6-BB9E-13F2D9F87BE8</uid>
<modDate>2020-04-07 17:16:18 +1000</modDate>
</2>

</_attr>
<sequence>
<3>
<_attr>
<2>
<tcStart>0s</tcStart>
<tcFormat>NDF</tcFormat>
<audioRate>48k</audioRate>
<format>r1</format>
<duration>250300/2500s</duration>
<audioLayout>stereo</audioLayout>
</2>

...
</resources>
</fcpxml>

Any ideas what's going wrong? Thanks in advance!

Stay safe during these crazy times!

manoelcampos commented 4 years ago

Hello @latenitefilms I appreciate the library is being useful. Unfortunately, I'm afraid your XML is too large and I don't have time to check it. Check the section "Converting a Lua Table to an XML String" in the README and see if it works.

Stay safe.

manoelcampos commented 4 years ago

The way it prints doesn't match the XML structure, but the Lua table structure. If you try to convert from Lua do XML again, it may work.

latenitefilms commented 4 years ago

No worries at all @manoelcampos!

Sadly I wasn't able to get it work the way I needed after playing around and reviewing the examples, documentation and code itself, so have gone with another solution, so all good.

Thanks for the fast response!

manoelcampos commented 4 years ago

Hey @latenitefilms Check the latest release and PR #40. Maybe it fixes your issue.