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

Comments are not handled while XML parsing. #30

Open
hyadav5 opened this issue Jul 28, 2017 · 1 comment
Open

Comments are not handled while XML parsing. #30

hyadav5 opened this issue Jul 28, 2017 · 1 comment

Comments

@hyadav5
Copy link

hyadav5 commented Jul 28, 2017

I know this is not the issue but a new request, but I feel this should be handled.
I have a below XML:

<Benchmark xmlns="http://checklists.nist.gov/xccdf/1.1" xml:lang="en-US">
 <Profile id="profile1">
    <title xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">text1</title>
    <select idref="This is rule 1" selected="true"/>
    <!--Rule:world_writable_sticky_dirs uses following values:-->
    <!--Rule:world_writable_sticky_dirs uses following values:-->
    <set-value idref="ssfs_master_key_timeout">20</set-value>
 </Profile> 

 <Profile id="profile2">
    <title xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">text2</title>
    <select idref="this is rule1" selected="true"/>
    <!--Rule:world_writable_sticky_dirs uses following values:-->
    <!--Rule:world_writable_sticky_dirs uses following values:-->
    <select idref="this is rule1" selected="true"/>
 </Profile>
</Benchmark>

Below is my code:
var fs = require('fs'); 
var et = require('elementtree');
var pd = require('pretty-data').pd;
var tailorData, etree;

tailorData = fs.readFileSync('my.xml').toString();

**etree = et.parse(tailorData); // This function misses all the comments section. So while writing etree to file, comments will be gone.**

var profile = etree.find('./Profile');
profile.set('id', 'MyElementTree');
var resultXml = etree.write();
fs.writeFileSync(tailoredXML, resultXml);

Their is no handler for comments.
NPM\elementtree\lib\parsers\sax.js:
XMLParser.prototype._handleComment = function(comment) {};

Is there any way I can include comments also in et.parse(), as these comments are important in my case ??? I have seen the below file of the elementtree npm, but didn't got idea how to handle the comments section.
NPM\elementtree\lib\parsers\sax.js
NPM\elementtree\lib\treebuilder.js

@Aarbel
Copy link

Aarbel commented Mar 14, 2018

@Kami @pquerna could you allow comments handling while xml parsing ?
Many people request for libraries which use elementtree (SamVerschueren/gulp-cordova-version#5 for example)
Thanks a lot !

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

2 participants