Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
Hyperledger Fabric chaincode error due to wrong javascript xml to string conversion

I currently have a fully functional chaincode developed in Java. One of the transactions involves as input a string generated from an XML document. This transformation is done in a Java app and sent to the network via Java SDK. This is an extract:

Document xmlDoc = null;
String docPath = "test.xml";
File xmlDocFile = new File(docPath);
try {
            DocumentBuilder db = dbf.newDocumentBuilder();
            xmlDoc = db.parse(xmlDocFile);
            transformer = transformerFactory.newTransformer();
            DOMSource source = new DOMSource(xmlDoc);
            StringWriter strWriter = new StringWriter();
            StreamResult stResult = new StreamResult(strWriter);
            transformer.transform(source, stResult);
            String xmlString = strWriter.getBuffer().toString();
}
catch (Exception e) {
            e.printStackTrace();
        }

The generated string is fed to the transaction, which runs smoothly. In my chaincode i reconvert the string in a document and use XPATH to make some operations.

In Hyperledger Caliper there is a need to modify the workload module written in Javascript in order to run the tests. I have included a small script that should perform the same operation done in Java:

const xml2js = require('xml2js');
const fs = require('fs');
const parser = new xml2js.Parser({ attrkey: "ATTR" });
var newXmlString = "";
// this example reads the file synchronously
// you can read it asynchronously also
let xml_string = fs.readFileSync("test.xml", "utf8");

parser.parseString(xml_string, function(error, result) {
    if(error === null) {
        //console.log(result);
        const objectToXmlString = require('object-to-xml-string');
        const obj2xml = new objectToXmlString();
        newXmlString = obj2xml.convert(result);
    }
    else {
        console.log(error);
    }
});

If i use the string generated in Javascript i obtain peer0.org1.example.com:7051:chaincode response 500, Error during contract method execution So this string doesn't allow me to start chaincode. Do you have some advice on how to load and convert the XML document in an approriate way?

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!