From: Immanuel N. <imm...@gm...> - 2013-07-15 15:07:22
|
I have to admit that my last "problem" wasn't really a problem. But the following seems to me more tricky. I have two xml-files with a single element <test/> in it that look identical in a text editor. The only difference is that bad.xml has a "Byte Order Mark" in front that good.xml doesn't have. It becomes visible through a hexadump: $ hexdump -C good.xml 00000000 3c 74 65 73 74 2f 3e 0d 0a |<test/>..| 00000009 $ hexdump -C bad.xml 00000000 ef bb bf 3c 74 65 73 74 2f 3e 0d 0a |...<test/>..| 0000000c As the file name already suggest the good.xml can be loaded with Dan's local:get-remote-file-safe function, but it fails with bad.xml. Since this function involves the util:binary-to-string function, I tried it with the additional parameter "UTF-8"; i.e. util:binary-to-string($binary-file,"UTF-8"). But that doesn't help either ("UTF-8" seems to be the default anyway here). So may be the parse function cannot cope with "Byte Order Mark" in front. So what would be the right way to handle this initial "Byte Order Mark"? Immanuel 2013/7/8 Dan McCreary <dan...@gm...> > The result looks like it is binary encoded. You first need to convert the > binary to a string using util:binary-to-string($binary-file). > > The string then needs to be converted into XML using the parse() function. > > This wrapper function might help > > (: this is a safe version of get remote XML file and parse :) > declare function local:get-remote-file-safe($connection as xs:long, $path > as xs:string) as node() { > let $binary-file := ft-client:retrieve-resource($connection, $path) > let $string-of-file := util:binary-to-string($binary-file) > return > try {util:parse($string-of-file)} > catch exerr:EXXQDY0002 {<error>The input file is not well > formed.</error>} > catch * {<error>Unknown parse error on input file. The input > could not be parsed.</error>} > }; > > > |