Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected start or end tag when unmarshalling #223

Open
nfigay opened this issue Aug 12, 2019 · 3 comments
Open

Expected start or end tag when unmarshalling #223

nfigay opened this issue Aug 12, 2019 · 3 comments

Comments

@nfigay
Copy link

nfigay commented Aug 12, 2019

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.

@highsource
Copy link
Owner

I'd first check if ./Model_View.xml really delivers valid XML.

@nfigay
Copy link
Author

nfigay commented Aug 12, 2019

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.

@mikaello
Copy link

mikaello commented Apr 5, 2021

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) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants