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

Unexpected characters - even in the simplest scenario #49

Closed
jbotorek opened this issue Jul 11, 2017 · 3 comments
Closed

Unexpected characters - even in the simplest scenario #49

jbotorek opened this issue Jul 11, 2017 · 3 comments

Comments

@jbotorek
Copy link

Hello,
I am new to the "world" of aalto. Unfortunately, I am not able to make it run as expected - It keeps returning com.fasterxml.aalto.WFCException , even in the simplest scenario (e.g. http://www.cowtowncoder.com/blog/archives/2011/03/entry_451.html this old blog entry).
Here is my code:

byte[] XML = "<tag>Tove</tag>".getBytes();
AsyncXMLInputFactory xmlInputFactory = new InputFactoryImpl();
AsyncXMLStreamReader<AsyncByteArrayFeeder> asyncReader = xmlInputFactory.createAsyncFor(XML);
int inputPtr = 0;
int type;
do {
while ((type = asyncReader.next()) == AsyncXMLStreamReader.EVENT_INCOMPLETE) {
asyncReader.getInputFeeder().feedInput(XML, inputPtr++, 1);
if (inputPtr >= XML.length) {
asyncReader.getInputFeeder().endOfInput();
}
}
System.out.println("Got event of type: "+type);
} while (type != XMLEvent.END_DOCUMENT);
asyncReader.close();

It keeps mi returning:
com.fasterxml.aalto.WFCException: Unexpected character 't' (code 116) in epilog (unbalanced start/end tags?)

Do you know, how to feedInput to the feeder so that no Exception is thrown, please? What do I do wrong?

I utilize com.fasterxml.aalto-xml in the version 1.0.0.

Thank you for any help

@cowtowncoder
Copy link
Member

Ok. So, the problem here is that you are feeding the same input twice: first via createAsyncFor(), and then also byte-by-byte in loop. Error message is bit vague, and it really should try to explain the issue better (it is trying to see if we get a comment or processing instruction -- which would be valid -- but instead would get a tag which is illegal, as only single root is allowed).
I'll file a separate issue for better error message.

So: either pass input document in when construction, or feed it in chunks, but not both.

The other minor thing is that end marker should be indicated separately from feeding the last byte (otherwise the last byte might not be read). But I don't know if that causes problems here.

@yar-malik
Copy link

@cowtowncoder can you write correct code for it. I have been trying for a long time and I can find good documentation.

@cowtowncoder
Copy link
Member

@AaMalik Same problem here: please read my explanation. It is frustrating to be asked again after fully explaining the issue. And if you do not understand the issue, ask question about which part is specifically problematic.

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