0

I am using the following framework to build my xmls

https://www.npmjs.com/package/xmlbuilder

When I do the following

.ele('ATTACHMENTS','')
    .ele('ATTACHMENT', attachmentXML)

I have another attachmentXML which looks like this

attachmentXML = builder.create('ATTACHMENT','','',{headless:true})
    .ele('FILECONTENT',escape(content)).up()

<ATTACHMENTS>  
  &lt;ATTACHMENT&gt;
  &lt;FILECONTENT&gt;PK%03%04%

The xml inside my main xml is wrapped inside of &lt.; instead of < etc. How do I fix this?

0

1 Answer 1

1

I tried the following code and it seems to work fine. Can you check if this is what you want?

var builder = require("xmlbuilder");

var xml = builder.create("root").ele("ATTACHMENTS");

for (var i = 0; i < 10; i++) {
    xml.ele("ATTACHMENT").ele("FILECONTENT", Math.random());
}

console.log(xml.end({ pretty: true }));

output

<?xml version="1.0"?>
<root>
  <ATTACHMENTS>
    <ATTACHMENT>
      <FILECONTENT>0.31942928777141466</FILECONTENT>
    </ATTACHMENT>
    <ATTACHMENT>
      <FILECONTENT>0.16859524100899814</FILECONTENT>
    </ATTACHMENT>
    <ATTACHMENT>
      <FILECONTENT>0.4068207368854062</FILECONTENT>
    </ATTACHMENT>
    <ATTACHMENT>
      <FILECONTENT>0.044208161687968595</FILECONTENT>
    </ATTACHMENT>
    <ATTACHMENT>
      <FILECONTENT>0.18556505055049022</FILECONTENT>
    </ATTACHMENT>
    <ATTACHMENT>
      <FILECONTENT>0.1554230424004983</FILECONTENT>
    </ATTACHMENT>
    <ATTACHMENT>
      <FILECONTENT>0.08717157045974977</FILECONTENT>
    </ATTACHMENT>
    <ATTACHMENT>
      <FILECONTENT>0.27141852241595643</FILECONTENT>
    </ATTACHMENT>
    <ATTACHMENT>
      <FILECONTENT>0.7834843228518138</FILECONTENT>
    </ATTACHMENT>
    <ATTACHMENT>
      <FILECONTENT>0.14114625574824502</FILECONTENT>
    </ATTACHMENT>
  </ATTACHMENTS>
</root>
Sign up to request clarification or add additional context in comments.

1 Comment

I am still seeing special characters in my case. I think the problem is with the special characters. I am getting the child XML fine. I will wait for other answers and accept it after some time as this is the best answer available right now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.