jsonix
jsonix copied to clipboard
Expected start or end tag when unmarshalling
I'm currently assessing jsonix as a component for an open souce capability for Enterprise Models visualisation. From an XML schema, I created the P0 mapping. I then referenced it for unmarshaling an xml file created according to the schema. But I had the message error indicated in the title. I tried it with a simpler schema, but had the same error message. I've difficulties interpreting where the problem comes from. Error message is the following: `/Users/nicolasfigay/node_modules/jsonix/jsonix.js:1298 throw new Error('Expected start or end tag.'); ^
Error: Expected start or end tag. at Object.nextTag (/Users/nicolasfigay/node_modules/jsonix/jsonix.js:1298:10) at Object.unmarshalDocument (/Users/nicolasfigay/node_modules/jsonix/jsonix.js:2129:9) at /Users/nicolasfigay/node_modules/jsonix/jsonix.js:2099:18 at /Users/nicolasfigay/node_modules/jsonix/jsonix.js:164:8 at Object.handleTransport (/Users/nicolasfigay/node_modules/jsonix/jsonix.js:309:7) at transport.onreadystatechange (/Users/nicolasfigay/node_modules/jsonix/jsonix.js:298:13) at dispatchEvent (/Users/nicolasfigay/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:591:25) at setState (/Users/nicolasfigay/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:610:14) at handleError (/Users/nicolasfigay/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:532:5) at ClientRequest.errorHandler (/Users/nicolasfigay/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:459:14)`
Code is the following: `ar http = require('http'); var fs = require('fs'); var Jsonix = require('jsonix').Jsonix; var PO = require('./PO.js').PO;
http.createServer(function (req, res) {
// First we construct a Jsonix context - a factory for unmarshaller (parser) // and marshaller (serializer) var context = new Jsonix.Context([PO]);
// Then we create a unmarshaller var unmarshaller = context.createUnmarshaller();
unmarshaller.unmarshalURL('./Model_View.xml', function (unmarshalled) { console.log('OK'); });
res.writeHead(200, {'Content-Type': 'text/html'}); res.end('Hello World!'); }).listen(8080);`
Any idea concerning the origin of the error?
Best regards.
I'd first check if ./Model_View.xml
really delivers valid XML.
Thanks for your quick response. After multiple changes, I identified the issue came from usage of unmarshaling with URL which was probably invalid. Using UnmarshalFile with node.js worked well. It was not very easy identifying the problem with the error message. Best regards.
I had the exact same mistake, copy pasted the example from the README, with unmarshallURL
and a local file. Changing to unmarshalFile
solved the issue for me:
// Unmarshal an object from the XML retrieved from the URL
- unmarshaller.unmarshalURL('po.xml',
+ unmarshaller.unmarshalFile('po.xml',
// This callback function will be provided
// with the result of the unmarshalling
function (unmarshalled) {