Problem in printing angle brackets using the xml-builder node module
up vote
1
down vote
favorite
I am creating an xml file using "xml-builder" node module. But when I tried to write angle brackets ("<" or ">"), I got characters like "<" and ">". The code is as follows:
let builder = require('xmlbuilder', { encoding: 'utf-8' });
let name = "ABC";
let xml = builder.create('Slides');
xml.ele('props',"Hello").up();
xml.ele('name',"<Hello> "+name+" </Hello>").up();
xml.end({ pretty: true });
console.log(xml.toString())
The output is as follows:
<Slides>
<props>Hello</props>
<name><Hello> ABC </Hello></name>
</Slides>
What should I do to get <
or >
printed instead of <
or >
?
javascript node.js npm xml-builder
add a comment |
up vote
1
down vote
favorite
I am creating an xml file using "xml-builder" node module. But when I tried to write angle brackets ("<" or ">"), I got characters like "<" and ">". The code is as follows:
let builder = require('xmlbuilder', { encoding: 'utf-8' });
let name = "ABC";
let xml = builder.create('Slides');
xml.ele('props',"Hello").up();
xml.ele('name',"<Hello> "+name+" </Hello>").up();
xml.end({ pretty: true });
console.log(xml.toString())
The output is as follows:
<Slides>
<props>Hello</props>
<name><Hello> ABC </Hello></name>
</Slides>
What should I do to get <
or >
printed instead of <
or >
?
javascript node.js npm xml-builder
Replace them with<
etc...
– Zohir Salak
Nov 9 at 4:15
1
Still not getting desired output
– Kushagra Sinha
Nov 9 at 5:12
please review my answer @KushagraSinha , leave a comment if it doesn't work or accept it if it does
– mihai
Nov 10 at 9:57
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am creating an xml file using "xml-builder" node module. But when I tried to write angle brackets ("<" or ">"), I got characters like "<" and ">". The code is as follows:
let builder = require('xmlbuilder', { encoding: 'utf-8' });
let name = "ABC";
let xml = builder.create('Slides');
xml.ele('props',"Hello").up();
xml.ele('name',"<Hello> "+name+" </Hello>").up();
xml.end({ pretty: true });
console.log(xml.toString())
The output is as follows:
<Slides>
<props>Hello</props>
<name><Hello> ABC </Hello></name>
</Slides>
What should I do to get <
or >
printed instead of <
or >
?
javascript node.js npm xml-builder
I am creating an xml file using "xml-builder" node module. But when I tried to write angle brackets ("<" or ">"), I got characters like "<" and ">". The code is as follows:
let builder = require('xmlbuilder', { encoding: 'utf-8' });
let name = "ABC";
let xml = builder.create('Slides');
xml.ele('props',"Hello").up();
xml.ele('name',"<Hello> "+name+" </Hello>").up();
xml.end({ pretty: true });
console.log(xml.toString())
The output is as follows:
<Slides>
<props>Hello</props>
<name><Hello> ABC </Hello></name>
</Slides>
What should I do to get <
or >
printed instead of <
or >
?
javascript node.js npm xml-builder
javascript node.js npm xml-builder
edited Nov 9 at 13:06
mihai
23.1k73968
23.1k73968
asked Nov 9 at 4:11
Kushagra Sinha
164
164
Replace them with<
etc...
– Zohir Salak
Nov 9 at 4:15
1
Still not getting desired output
– Kushagra Sinha
Nov 9 at 5:12
please review my answer @KushagraSinha , leave a comment if it doesn't work or accept it if it does
– mihai
Nov 10 at 9:57
add a comment |
Replace them with<
etc...
– Zohir Salak
Nov 9 at 4:15
1
Still not getting desired output
– Kushagra Sinha
Nov 9 at 5:12
please review my answer @KushagraSinha , leave a comment if it doesn't work or accept it if it does
– mihai
Nov 10 at 9:57
Replace them with
<
etc...– Zohir Salak
Nov 9 at 4:15
Replace them with
<
etc...– Zohir Salak
Nov 9 at 4:15
1
1
Still not getting desired output
– Kushagra Sinha
Nov 9 at 5:12
Still not getting desired output
– Kushagra Sinha
Nov 9 at 5:12
please review my answer @KushagraSinha , leave a comment if it doesn't work or accept it if it does
– mihai
Nov 10 at 9:57
please review my answer @KushagraSinha , leave a comment if it doesn't work or accept it if it does
– mihai
Nov 10 at 9:57
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
There is an npm module decode-html that will handle the same use case as your.
var decode = require('decode-html');
console.log(decode('<div class="hidden">NON&SENSE's</div>'));
// -> '<div class="hidden">NON&SENSE's</div>'
1
Still not getting desired output
– Kushagra Sinha
Nov 9 at 5:21
add a comment |
up vote
0
down vote
The problem is that is you are attempting to create a child element in an incorrect way, by passing some xml in the value
field of xml.ele
. The module is correctly escaping your angle brackets.
What you need to do is create another element named Hello
and append it to the name
element. You can do this by either chaining your .ele
calls or using their return values.
Here is the correct code:
let builder = require('xmlbuilder', { encoding: 'utf-8' });
let name = "ABC";
let xml = builder.create('Slides');
xml.ele('props',"Hello");
xml.ele('name')
.ele("Hello", name);
xml.end({ pretty: true });
console.log(xml.toString())
Output:
<Slides>
<props>Hello</props>
<name>
<Hello>ABC</Hello>
</name>
</Slides>
Sir, actually I have to create "cdata" section in the xml file. Ex: "<notestext><![CDATA[{Notes Text}]]></notestext>". How to create that cdata section?
– Kushagra Sinha
Nov 10 at 10:36
See github.com/oozcitak/xmlbuilder-js/wiki#cdata-nodes or ask a different question
– mihai
Nov 10 at 10:39
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219765%2fproblem-in-printing-angle-brackets-using-the-xml-builder-node-module%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
There is an npm module decode-html that will handle the same use case as your.
var decode = require('decode-html');
console.log(decode('<div class="hidden">NON&SENSE's</div>'));
// -> '<div class="hidden">NON&SENSE's</div>'
1
Still not getting desired output
– Kushagra Sinha
Nov 9 at 5:21
add a comment |
up vote
0
down vote
There is an npm module decode-html that will handle the same use case as your.
var decode = require('decode-html');
console.log(decode('<div class="hidden">NON&SENSE's</div>'));
// -> '<div class="hidden">NON&SENSE's</div>'
1
Still not getting desired output
– Kushagra Sinha
Nov 9 at 5:21
add a comment |
up vote
0
down vote
up vote
0
down vote
There is an npm module decode-html that will handle the same use case as your.
var decode = require('decode-html');
console.log(decode('<div class="hidden">NON&SENSE's</div>'));
// -> '<div class="hidden">NON&SENSE's</div>'
There is an npm module decode-html that will handle the same use case as your.
var decode = require('decode-html');
console.log(decode('<div class="hidden">NON&SENSE's</div>'));
// -> '<div class="hidden">NON&SENSE's</div>'
answered Nov 9 at 4:57
front_end_dev
1,3151511
1,3151511
1
Still not getting desired output
– Kushagra Sinha
Nov 9 at 5:21
add a comment |
1
Still not getting desired output
– Kushagra Sinha
Nov 9 at 5:21
1
1
Still not getting desired output
– Kushagra Sinha
Nov 9 at 5:21
Still not getting desired output
– Kushagra Sinha
Nov 9 at 5:21
add a comment |
up vote
0
down vote
The problem is that is you are attempting to create a child element in an incorrect way, by passing some xml in the value
field of xml.ele
. The module is correctly escaping your angle brackets.
What you need to do is create another element named Hello
and append it to the name
element. You can do this by either chaining your .ele
calls or using their return values.
Here is the correct code:
let builder = require('xmlbuilder', { encoding: 'utf-8' });
let name = "ABC";
let xml = builder.create('Slides');
xml.ele('props',"Hello");
xml.ele('name')
.ele("Hello", name);
xml.end({ pretty: true });
console.log(xml.toString())
Output:
<Slides>
<props>Hello</props>
<name>
<Hello>ABC</Hello>
</name>
</Slides>
Sir, actually I have to create "cdata" section in the xml file. Ex: "<notestext><![CDATA[{Notes Text}]]></notestext>". How to create that cdata section?
– Kushagra Sinha
Nov 10 at 10:36
See github.com/oozcitak/xmlbuilder-js/wiki#cdata-nodes or ask a different question
– mihai
Nov 10 at 10:39
add a comment |
up vote
0
down vote
The problem is that is you are attempting to create a child element in an incorrect way, by passing some xml in the value
field of xml.ele
. The module is correctly escaping your angle brackets.
What you need to do is create another element named Hello
and append it to the name
element. You can do this by either chaining your .ele
calls or using their return values.
Here is the correct code:
let builder = require('xmlbuilder', { encoding: 'utf-8' });
let name = "ABC";
let xml = builder.create('Slides');
xml.ele('props',"Hello");
xml.ele('name')
.ele("Hello", name);
xml.end({ pretty: true });
console.log(xml.toString())
Output:
<Slides>
<props>Hello</props>
<name>
<Hello>ABC</Hello>
</name>
</Slides>
Sir, actually I have to create "cdata" section in the xml file. Ex: "<notestext><![CDATA[{Notes Text}]]></notestext>". How to create that cdata section?
– Kushagra Sinha
Nov 10 at 10:36
See github.com/oozcitak/xmlbuilder-js/wiki#cdata-nodes or ask a different question
– mihai
Nov 10 at 10:39
add a comment |
up vote
0
down vote
up vote
0
down vote
The problem is that is you are attempting to create a child element in an incorrect way, by passing some xml in the value
field of xml.ele
. The module is correctly escaping your angle brackets.
What you need to do is create another element named Hello
and append it to the name
element. You can do this by either chaining your .ele
calls or using their return values.
Here is the correct code:
let builder = require('xmlbuilder', { encoding: 'utf-8' });
let name = "ABC";
let xml = builder.create('Slides');
xml.ele('props',"Hello");
xml.ele('name')
.ele("Hello", name);
xml.end({ pretty: true });
console.log(xml.toString())
Output:
<Slides>
<props>Hello</props>
<name>
<Hello>ABC</Hello>
</name>
</Slides>
The problem is that is you are attempting to create a child element in an incorrect way, by passing some xml in the value
field of xml.ele
. The module is correctly escaping your angle brackets.
What you need to do is create another element named Hello
and append it to the name
element. You can do this by either chaining your .ele
calls or using their return values.
Here is the correct code:
let builder = require('xmlbuilder', { encoding: 'utf-8' });
let name = "ABC";
let xml = builder.create('Slides');
xml.ele('props',"Hello");
xml.ele('name')
.ele("Hello", name);
xml.end({ pretty: true });
console.log(xml.toString())
Output:
<Slides>
<props>Hello</props>
<name>
<Hello>ABC</Hello>
</name>
</Slides>
edited Nov 9 at 13:25
answered Nov 9 at 13:11
mihai
23.1k73968
23.1k73968
Sir, actually I have to create "cdata" section in the xml file. Ex: "<notestext><![CDATA[{Notes Text}]]></notestext>". How to create that cdata section?
– Kushagra Sinha
Nov 10 at 10:36
See github.com/oozcitak/xmlbuilder-js/wiki#cdata-nodes or ask a different question
– mihai
Nov 10 at 10:39
add a comment |
Sir, actually I have to create "cdata" section in the xml file. Ex: "<notestext><![CDATA[{Notes Text}]]></notestext>". How to create that cdata section?
– Kushagra Sinha
Nov 10 at 10:36
See github.com/oozcitak/xmlbuilder-js/wiki#cdata-nodes or ask a different question
– mihai
Nov 10 at 10:39
Sir, actually I have to create "cdata" section in the xml file. Ex: "<notestext><![CDATA[{Notes Text}]]></notestext>". How to create that cdata section?
– Kushagra Sinha
Nov 10 at 10:36
Sir, actually I have to create "cdata" section in the xml file. Ex: "<notestext><![CDATA[{Notes Text}]]></notestext>". How to create that cdata section?
– Kushagra Sinha
Nov 10 at 10:36
See github.com/oozcitak/xmlbuilder-js/wiki#cdata-nodes or ask a different question
– mihai
Nov 10 at 10:39
See github.com/oozcitak/xmlbuilder-js/wiki#cdata-nodes or ask a different question
– mihai
Nov 10 at 10:39
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219765%2fproblem-in-printing-angle-brackets-using-the-xml-builder-node-module%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Replace them with
<
etc...– Zohir Salak
Nov 9 at 4:15
1
Still not getting desired output
– Kushagra Sinha
Nov 9 at 5:12
please review my answer @KushagraSinha , leave a comment if it doesn't work or accept it if it does
– mihai
Nov 10 at 9:57