Page 2 of 2
Re: [PB5.7 B4] ExportXML() missing characters
Posted: Sat Dec 22, 2018 5:03 pm
by ccode
No idea!
Code: Select all
;????
xml = LoadXML(#PB_Any, "test.xml")
Define size.i = ExportXMLSize(xml)
Debug "xml-FileSize: " + size
Define size2.i = FileSize("test.xml")
Debug "FileSize: " + size2
Define *buffer = AllocateMemory(size2)
If ExportXML(xml, *buffer, size2)
Debug PeekS(*buffer, -1, #PB_UTF8)
EndIf
FreeMemory(*buffer)
Re: [PB5.7 B4] ExportXML() missing characters
Posted: Sat Dec 22, 2018 8:47 pm
by #NULL
I assume 'test.xml' is the snippet from my previous post? I don't think FileSize() makes sense here, but I get your point, i.e. that it works with FileSize()? But it also works with the size from ExportXMLSize() + 8. My guess is that the 5 characters of an entity are counted as 1 for the represented character (CR or LF etc) due to some internal conversion, missing 4 character counts per entity. Two entities makes that 8.
Another thing is that the entities get converted from hexadecimal to decimal in the output. Don't know if that counts as a bug.
Re: [PB5.7 B4] ExportXML() missing characters
Posted: Sat Dec 22, 2018 9:50 pm
by ccode
Hello #NULL !
"test.xml" = It's your example xml text.
Output:
xml-FileSize: 761
FileSize: 772
<?xml version="1.0" encoding="UTF-8"?>
<hixz Source="Living Cookbook 4.0" FileVersion="1.0" date="2013-09-21">
<Cookbooks>
<Cookbook Name="Imported" ID="29"/>
</Cookbooks>
<CookbookChapters>
<CookbookChapter Name="Bisques, Chili, Chowders, Gumbows, Soups & Stews" ID="364" CookbookID="29" ParentChapterID="0"/>
<CookbookChapter Name="Stews *" ID="365" CookbookID="29" ParentChapterID="364"/>
</CookbookChapters>
<Recipes>
<Recipe Name="Chickpea Stew" ID="11007" CookbookID="29" CookbookChapterID="365" Comments="rice. Garam masala " Source="Williams-Sonoma" WebPage="
http://www.williams-sonoma.com/recipe/c ... CIPESEARCH" CreateDate="2012-02-19" ColorFlag="<None>">
</Recipe>
</Recipes>
</hixz>
Re: [PB5.7 B4] ExportXML() missing characters
Posted: Sat Dec 22, 2018 10:37 pm
by #NULL
The file size contains 3 additional bytes for the BOM, plus the 8 missing from ExportXMLSize() makes the difference of 11. (I get a difference of 14 here though, don't know why)
Re: [PB5.7 B4] ExportXML() missing characters
Posted: Thu Jan 03, 2019 12:10 am
by NicTheQuick
Okay, the final version is out but this bug was not fixed. Is there a known workaround for this?
Re: [PB5.7 B4] ExportXML() missing characters
Posted: Thu Jan 03, 2019 2:00 am
by Little John
Hi,
using
this code from #NULL, I can confirm the problem with PB 5.62 (x64) on Linux Mint 18.3 and on Windows 10, as well with PB 5.70 beta 4 on Windows 10.
NicTheQuick wrote:Is there a known workaround for this?
As a workaround, the following code seems to work here with the above mentioned PB versions and operating systems:
Code: Select all
; slightly changed after <https://www.purebasic.fr/english/viewtopic.php?p=530436#p530436>
EnableExplicit
Define xml.i = LoadXML(#PB_Any, "Recipes.xml")
Define encoding.i = GetXMLEncoding(xml)
Define size.i = ExportXMLSize(xml) + 100
Define *buffer = AllocateMemory(size)
Debug size
Debug ""
If ExportXML(xml, *buffer, size)
; ShowMemoryViewer(*buffer, size)
Debug PeekS(*buffer, -1, encoding)
EndIf
FreeMemory(*buffer)
So I also think that the cause of the problem is a wrong return value of
ExportXMLSize().
I guess that using something like
might be safe for all "normal" XML files.
Re: [PB5.7 B4] ExportXML() missing characters
Posted: Sat Jul 27, 2024 5:39 pm
by Fred
After investigation, the XML you try to parse was not correct (it included an '&' in an attribute while it should be escaped with &). After adding the proper error code check, it pointed out the error and that's why your XML was truncated (because everything which is already parsed is kept).
Code: Select all
; slightly changed after <https://www.purebasic.fr/english/viewtopic.php?p=530436#p530436>
Define xml.i = LoadXML(#PB_Any, "crash.xml")
; Display an error message if there was a markup error
;
If XMLStatus(xml) <> #PB_XML_Success
Message$ = "Error in the XML file:" + Chr(13)
Message$ + "Message: " + XMLError(xml) + Chr(13)
Message$ + "Line: " + Str(XMLErrorLine(xml)) + " Character: " + Str(XMLErrorPosition(xml))
MessageRequester("Error", Message$)
End
EndIf
Define encoding.i = GetXMLEncoding(xml)
Define size.i = ExportXMLSize(xml) + 100
Define *buffer = AllocateMemory(size)
Debug size
Debug ""
If ExportXML(xml, *buffer, size)
; ShowMemoryViewer(*buffer, size)
Debug PeekS(*buffer, -1, encoding)
EndIf
FreeMemory(*buffer)
Re: ExportXML() missing characters
Posted: Sat Jul 27, 2024 10:35 pm
by boddhi
@Fred
Mieux vaut tard que jamais !
