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

using a xml prolog leads to an error within xml literal #9275

Closed
JensWalter opened this issue Jun 28, 2018 · 5 comments
Closed

using a xml prolog leads to an error within xml literal #9275

JensWalter opened this issue Jun 28, 2018 · 5 comments

Comments

@JensWalter
Copy link
Contributor

Description:
If I set a prolog for a xml literal, ballerina fails with "mismatched input '<'. expecting XMLLiteralEnd".
Since xml instructions are supported, setting a prolog inline should also be supported.

Steps to reproduce:
Constructing a xml literal with xml prolog leads to an error.

import ballerina/io;

function main (string... args){
    xml x1 = xml`<?xml version="1.0" encoding="UTF-8"?>`; //works
    xml x2 = xml`<root/>`; //works
    xml x3 = x1+x2; //works
    xml x4 = xml`<?xml version="1.0" encoding="UTF-8"?><root/>`; //does not work
    xml x5 = xml`<root>hallo<?char 12?></root>`; //works
}

Affected Versions:
0.976.0

Related Issues (optional):

Suggested Labels (optional):
Type/Bug

Suggested Assignees (optional):

@SupunS
Copy link
Contributor

SupunS commented Jun 28, 2018

Hi @JensWalter,

XML Literal (xml `some content`) only allows to parse a single xml item (a single element, text, comment or a processing instruction). However in xml x4 = xml`<?xml version="1.0" encoding="UTF-8"?><root/>`; it contains two items within the literal. Thats why it fails.

This behavior is intended. But I agree that the error message is not very intuitive, as it is thrown from the parser.

The solution is to define them separately, and concat them, as you have done with x1, x2 and x3.

@JensWalter
Copy link
Contributor Author

This is indeed not self explanatory and very inconvenient for constructing XMLs. Is there any other way to generate the Prolog after the xml is constructed?

@SupunS
Copy link
Contributor

SupunS commented Jun 28, 2018

At the moment, there's no alternative way, but to concat the prolog to the xml element..

@JensWalter
Copy link
Contributor Author

You just added a label to this when I was about to close this issue.
From my point of view, this is a 'works as designed' case, and therefore can be closed.

@SupunS
Copy link
Contributor

SupunS commented Jul 4, 2018

@JensWalter Great! Im closing the issue as per your reply. Please do reopen, if you encounter any other issue related to this.

@SupunS SupunS closed this as completed Jul 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants