Closed Code-Crash closed 4 years ago
This was introduced in v7.0. The ’instruction‘ function now inserts the processing instruction node as a child of its parent node. For the old behavior you need to use the ‘instructionBefore‘ function. Please see: https://github.com/oozcitak/xmlbuilder-js/wiki#processing-instructions
@oozcitak, Thanks for the doc link and details, I will check it today.
@oozcitak, Yes it worked. Thanks.
Can we also add one example in the doc?
If yes, I can create a small PR for the same?
@Code-Crash Yes sure. Thank you in advance.
@oozcitak Okay, I will submit the PR in some time.
Hi @oozcitak,
I cloned and created a new branch of wiki repo, but unable to push due to permission issue.
please add the following code as here to update the doc or If I get permission, I will do the same.
`
XML processing instructions are created with the instruction
function (can also be abbreviated to ins
or i
).
ele.ins('xml-stylesheet', 'type="text/xsl" href="style.xsl"');
There are also the instructionBefore
and instructionAfter
functions for processing instructions. They accept the same arguments as the instruction
function.
ins
, instructionBefore
and instructionAfter
will return their parent node.
using instructionBefore
, will add an instruction before the root element.
var foo = xmlbuilder.create('Foo', {
version: '1.0',
encoding: 'utf-8'
}).instructionBefore('bar', 'version="13.0"');
var xml = foo.end({
'pretty': true
});
// xml string output
<?xml version="1.0" encoding="utf-8"?>
<?bar version="13.0"?>
<Foo/>
using instruction
, will add an instruction immediately inside after the root element.
var foo = xmlbuilder.create('Foo', {
version: '1.0',
encoding: 'utf-8'
}).instruction('bar', 'version="13.0"');
var xml = foo.end({
'pretty': true
});
// xml string output
<?xml version="1.0" encoding="utf-8"?>
<Foo>
<?bar version="13.0"?>
</Foo>
using instructionAfter
, will add a instruction after the root element.
var foo = xmlbuilder.create('Foo', {
version: '1.0',
encoding: 'utf-8'
}).instructionAfter('bar', 'version="13.0"');
var xml = foo.end({
'pretty': true
});
// xml string output
<?xml version="1.0" encoding="utf-8"?>
<Foo/>
<?bar version="13.0"?>
`
I changed the formatting a bit and added to the wiki: https://github.com/oozcitak/xmlbuilder-js/wiki/Home/_compare/4fc917165e0ffadeeba5b80bc148f2b3159c3bdf...6f85e2fe86b2e96818eb9dd71ec9c9f4c19503eb
Thank you
@oozcitak Thank you too.
Hi Team,
I'm using this library for more than 2 years for my personal project, suddenly I found an issue in the new version('13.0.2') for creating an instruction before the root element.
Earlier, I was using '2.6.4' and it was working fine.
kindly go through the following example:
The codebase is the same as always:
in version 2.6.4 I was getting the output XML as below:
in version 13.0.2, I was getting the output XML as below:
Please see the difference for
<?qbxml version="13.0"?>
, I want this after<?xml version="1.0" encoding="utf-8"?>
and before<QBXML>
.It is working fine when I did change the version back to '2.6.4'.
Thanks