Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

problem loading Unicode Xml file (no utf8)

I'm using Msxml2.DOMDocument and its method load() for loading xml documents.
it's work fine when loading asci files or UTF-8 files but when i want to load Unicode (16bit) files it want work.
I dont get any error message but my document seems empty with no nodes at all.

Here's my example xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v4.3 U (http://www.xmlspy.com) by fonis (fon) -->
     <opis-strane>Najnovije informacije</opis-strane>
     <novost id="new">
          <naslov>Primeri za kolokvijum</naslov>
               Postavljeni primeri za vežbanje kolokvijuma iz Baza Podataka koji æe se održati u subotu u 08:00
          <jos type="xml" href="literatura-primeri.xml"/>

Can someone give me solution ?
1 Solution
I assume you are loading a FILE not a stream from a web server. In this case :-

1) replace the encoding="utf-8" with encoding="ucs-2"
   omit it totally

2) Ensure that the file is stored in Unicode format.

   On WinNT/Win2K use NotePad to store the file in Unicode format.

Files stored in Unicode format (on Intel machines) are stored in Lendian format (=little end). This means that each 16-bit character is stored as two characters with the lower valued byte (=wchar MOD 65536) first (lower address) and the higher valued byte (=wchar DIV 65536) second (higher address). Additionally the start of the file is marked by two bytes FF FE

The parser will notice the first two bytes and will decode the rest of the file properly.

Incidentally, utf-8 files have the first three bytes as EF BB BF.

cubrovicAuthor Commented:
Now it seems that working but i do it earlier (not ucs-2 but unicode) .I handle my xml files in xmlspy and it change it automaticly.Anyway if i have problems in future with it that will be new question with new points.
I thought that ms domDocument not working with 16 bit characters at all.
Thanks man.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now