0

I am using TXMLDocument to process a PAD file at http://repository.appvisor.com/info/app-9f00e7003a57/DataNumen_Access_Repair_pad.xml

Below is my code(XML Vendor is MSXML):

procedure ProcessFile1(const SrcFileName: string);
var
  XmlFile: IXMLDocument;
begin
  XmlFile := TXMLDocument.Create(nil);
  try
    XmlFile.LoadFromFile(SrcFileName);
    XmlFile.SaveToFile(SrcFileName)
  finally
  end;
end;

My codes just load the file and then save it. The saved version is at https://www.datanumen.com/temp/pad/DataNumen_Access_Repair_pad1.xml

I use WinMerge to compare the two versions, and find the entities are all deleted in the saved version.

enter image description here

How to prevent this?

5
  • No idea why this is happening. Character #13 is a return character. For some reason the code is escaping a special character when it should not (see : en.wikipedia.org/wiki/…). My best guess is the encoding for xml is utf-8. The character is not utf-8 and is escaping. I think you have a unicode return character in the file that should be a utf-8 return character.
    – jdweng
    Sep 25 at 12:54
  • 4
    Let WinMerge not ignore different line breakings, then you should see it's not gone but instead just resolved to an actual byte of the value 13. Or display both in a hex viewer. Neither a "unicode return character" nor a "a utf-8 return character" [sic] exists - entities are unbound to text encodings - that's their main purpose.
    – AmigoJack
    Sep 25 at 15:12
  • @AmigoJack, After carefully checking the binary data, it is the case.
    – alancc
    Sep 25 at 16:38
  • You can upvote comments if they helped you. Technically 
 is the same as having #13 directly - the XML engine parses your entire markup into a DOM, and when you want to save it to XML again it is re-translated from DOM to text. At that point nobody would care if the source had an entity or the appropriate byte(s). By using TXMLDocument you operate on the DOM, not on text. If you want it 1:1 then copy the text, not its interpretation. Changing .DOMVendor most likely won't help either.
    – AmigoJack
    Sep 25 at 20:04
  • 2
    The original XML content likely had CRLF line breaks in it, but whatever generator created the PAD file probably only supports LF and so escaped the CR. Then TXMLDocument unescaped the CR and saved it as a binary byte 0x13 (since it doesn't require escaping per the XML spec) alongside the original LF, thus producing a valid CRLF, which WinMerge displays normally. Sep 25 at 21:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.