-
Notifications
You must be signed in to change notification settings - Fork 73
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
Comments
yes, I've noticed that at well. Also any DTD node is lost with the DOM handler. |
Hello guys. I'm not being able to maintain this project and I'm looking for a maintainer that can take over it. |
Merged
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
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.
The text was updated successfully, but these errors were encountered: