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

Support for XML 1.1 schema files #34

Closed
sreejithsree139 opened this issue Aug 14, 2020 · 2 comments
Closed

Support for XML 1.1 schema files #34

sreejithsree139 opened this issue Aug 14, 2020 · 2 comments

Comments

@sreejithsree139
Copy link

I am converting my epub file URL to stream and saving to local DB as bytes like below:

Stream stream;
HttpClient client = new HttpClient();
var response = await client.GetAsync(fileUrl);
stream = await response.Content.ReadAsStreamAsync();
epubBook = EpubReader.ReadBook(stream);

//saving to folder
byte[] bytes = await response.Content.ReadAsByteArrayAsync();
string filename = Path.GetFileName(fileUrl);
var folderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var filePath = Path.Combine(folderPath, filename);
File.WriteAllBytes(filePath, bytes);

This is working fine for most of the files. But some file URLs showing System.AggregateException.

Exception Details

System.AggregateException: One or more errors occurred. (Version number '1.1' is invalid. Line 1, position 16.) ---> System.Xml.XmlException: Version number '1.1' is invalid. Line 1, position 16.
at System.Xml.XmlTextReaderImpl.Throw (System.Exception e) [0x00027] in <0757e7484a1349cca3b4558c721885b2>:0
at System.Xml.XmlTextReaderImpl.Throw (System.String res, System.String arg) [0x00029] in <0757e7484a1349cca3b4558c721885b2>:0
at System.Xml.XmlTextReaderImpl.ParseXmlDeclaration (System.Boolean isTextDecl) [0x0061f] in <0757e7484a1349cca3b4558c721885b2>:0
at System.Xml.XmlTextReaderImpl.Read () [0x000c6] in <0757e7484a1349cca3b4558c721885b2>:0
at System.Xml.Linq.XDocument.Load (System.Xml.XmlReader reader, System.Xml.Linq.LoadOptions options) [0x00016] in <89374192b20a41739cf7c5bb822846fe>:0
at System.Xml.Linq.XDocument.Load (System.IO.Stream stream, System.Xml.Linq.LoadOptions options) [0x0000f] in <89374192b20a41739cf7c5bb822846fe>:0
at System.Xml.Linq.XDocument.Load (System.IO.Stream stream) [0x00000] in <89374192b20a41739cf7c5bb822846fe>:0
at VersOne.Epub.Internal.XmlUtils+<>c__DisplayClass0_0.b__0 () [0x00000] in <7c46dbfe3ebf403389304a938822832e>:0
at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <46c2fa109b574c7ea6739f9fe2350976>:0
at System.Threading.Tasks.Task.Execute () [0x00000] in <46c2fa109b574c7ea6739f9fe2350976>:0
--- End of stack trace from previous location where exception was thrown ---

Sample file URLs having this issue:

https://s3.us-east-1.amazonaws.com/catholic-brain/prod/dc/cbrain-app/files/doc-lib/2020/08/10/12/56/42/068/head/9781612781495_EPUB.epub

https://s3.us-east-1.amazonaws.com/catholic-brain/prod/dc/cbrain-app/files/doc-lib/2020/08/10/07/36/06/376/head/9781612781358_EPUB.epub

I am using EpubReader.Cross Nuget for parsing the epub file.

I have uploaded a sample project for the easy reference.

@vers-one
Copy link
Owner

Yeah, .NET doesn't support XML 1.1 due to its low popularity and lack of widespread adoption. This pull request should provide a workaround for a majority of the cases and the pull request mentioned by @yunusefendi52 above should make this workaround more robust.

@vers-one vers-one changed the title Xamarin Forms - Epub: System.AggregateException: One or more errors occurred Support for XML 1.1 schema files Feb 24, 2022
@vers-one
Copy link
Owner

Looks like the easiest solution would be just to skip the XML header completely before passing the stream to the XDocument.

Implemented in PR #50.

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

Successfully merging a pull request may close this issue.

2 participants