Closed HollisMeynell closed 12 months ago
We're glad you find this project helpful. We'll try to address this issue ASAP. You can vist https://solothought.com to know recent features. Don't forget to star this repo.
When encountering the issue, I noticed that the type of the textValue
variable is function
.
Hi @HollisMeynell
I tried to build from the json 2 and get no error.
const opt = {
preserveOrder: false,
ignoreAttributes: false,
parseTagValue: true,
attributeNamePrefix: "$"
}
const parser = new XMLParser(opt);
const builder = new XMLBuilder(opt);
// let template = fs.readFileSync( path.join(__dirname,'assets/sp.svg')).toString();
// const jsObj = parser.parse(template);
const jsObj = require("./assets/sp_svg.json") // <---- json 2
builder.build(jsObj);
Hi @HollisMeynell
I tried to build from the json 2 and get no error.
const opt = { preserveOrder: false, ignoreAttributes: false, parseTagValue: true, attributeNamePrefix: "$" } const parser = new XMLParser(opt); const builder = new XMLBuilder(opt); // let template = fs.readFileSync( path.join(__dirname,'assets/sp.svg')).toString(); // const jsObj = parser.parse(template); const jsObj = require("./assets/sp_svg.json") // <---- json 2 builder.build(jsObj);
I've found the issue. Please try executing the following code anywhere before the builder.build(jsObj)
:
Object.prototype.setSvgText = function (str) {
this["#text"] = str;
}
Modifying Object.prototype
is not a good practice; it was my mistake in using it. I apologize for the inconvenience caused.
Description
I want to modify an SVG in a Node environment. I have successfully serialized it into a JavaScript object, but when trying to convert it back to XML, I encountered errors that I cannot resolve. I am providing the detailed output of the XML file and JSON.Perhaps I have misconfigured something, but I don't know how to set it up correctly, and I'm unsure of the proper configuration needed to preserve the attributes of the XML. As you can see, this is a piece of SVG code, and it may contain attributes with special characters, such as xlink:href.
Input
xml:
Code
Output
json 1
json 2
error
expected data
I would like to obtain a correct and attribute-containing XML.
Would you like to work on this issue?
Bookmark this repository for further updates. Visit SoloThought to know about recent features.