Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

Creating a DOM tree is missing XML declaration #79

Closed
geert56 opened this issue Jun 3, 2022 · 2 comments · Fixed by #86
Closed

Creating a DOM tree is missing XML declaration #79

geert56 opened this issue Jun 3, 2022 · 2 comments · Fixed by #86

Comments

@geert56
Copy link

geert56 commented Jun 3, 2022

Any XML declaration gets lost when parsing XML. Also, a ROOT type node is never created when using
the DOM handler.
As I understand it, the first tree node should be of type ROOT and when present should have the XML declaration as a child node under the DECL type. The first start element would then be the second child.
This is easy to fix in xmlhandler/dom.lua in the function dom:decl() by adding:
if self.root == nil then
self.root = self.current
end
before or after the table.insert.

On reflection, I think it is even better to always have a ROOT node in the DOM handler, so that top-level comments are also preserved as its children. This can be achieved by setting root=curent in the init() function.

@doj
Copy link
Contributor

doj commented Oct 24, 2022

yes, I've noticed that at well. Also any DTD node is lost with the DOM handler.
I've fixed that in my branch https://github.com/doj/xml2lua/tree/dom-fixes where I do create a ROOT node, which would contain the DECL node, DTD node and the root ELEMENT node.

@manoelcampos
Copy link
Owner

Hello guys. I'm not being able to maintain this project and I'm looking for a maintainer that can take over it.

manoelcampos added a commit that referenced this issue Feb 3, 2023
* correctly set a ROOT node as the first node of the dom object.
set the DECL node as the first child node of ROOT.
fix indent in dom:toXml().

* fix detection of an empty ELEMENT node.

* XmlParser: fix parsing of a DTD element.
dom handler: fix handling a DTD element.

* Fix dom.lua docs

* Rename people.xml to people1.xml
Moves complex tags (DOCTYPE and CDATA)
to people2.xml to make people1 a basic XML.

* Restructure example5.lua to
parse the XML files whose names
are defined by an array inside the example,
instead of receiving them in the STDIN.

This way, the entry to run this example
inside the Makefile were removed.
Running a specific example inside the Makefile
is too specific.

If that was for test purposes, they should be inside the test files.

---------

Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
Co-authored-by: Sudheer Hebbale <sudheer.hr@tekenlight.com>
Co-authored-by: Manoel Campos <manoelcampos@gmail.com>
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

Successfully merging a pull request may close this issue.

3 participants