Delphi+XML+UTF + € problem

HI,
I am importing an XML contains some special characters  to a TXMLDocument.

    FS:=TSL2FileStream.Create(XMLfile,fmShareDenyNone);
    XMLDOc.LoadFromStream(FS,xetUTF_16LELike);
    XMLDOc.active;

When I am extracting data, get a " ? " in the place of " € ".

Help me guys to resolve this.

Regards,
Vijesh V.Nair

LVL 1
udhnaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Eddie ShipmanAll-around developerCommented:
Have you tried UTF-8
0
developmentguruPresidentCommented:
What version of Delphi are you using?  What is the type of the stream you are creating?  I do not recognize it.
0
udhnaAuthor Commented:
Okay,
The UTF-8 is not Helped.

I am Using Delphi 7. The Stream Type is a descendant of TFileStream. I Tried with TFileStream too, Not worked.






0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Eddie ShipmanAll-around developerCommented:
Did you try xetUnknown to let the TXMLDocument try to figure out the encoding?
0
Eddie ShipmanAll-around developerCommented:
Where/what control are you extracting data to?
If the control doesn't support multi-byte chars, it may be the control you are trying to
read this XML into. Try saving the resulting XML into a new file to see if it is indeed parsing
the characters with the correct encoding.
0
udhnaAuthor Commented:
Thanks for the comments.
EddieShipman,  
          xetUnknown not helped.
         I saved the loaded xml. when I checked a special charector(not a Question Mark) ¿ is coming in place of €.

0
Eddie ShipmanAll-around developerCommented:
Well, my suggestion is to drop TXMLDocument entirely and go with IXMLDocument.
If you want to post some more of your code, I'll show you how to convert it.

I have NEVER liked TXMLDOcument because it is a "crutch" around the IXMLDocument COM object. I have been using IXMLDocument since 1999 so I'd rather use it than the crutch.
0
udhnaAuthor Commented:
Thanks EddieShipman,
I am getting error when loading xmlfile.

Var
   iXmlDoc  : IXMLDocument;
Begin
   iXmlDoc:=NewXMLDocument;
   iXmlDoc.LoadFromFile(sFileCurrency);



Kindly send me some sample code for loading and finding the nodes and values.






0
udhnaAuthor Commented:
the XMLDoc(TXMLDOCUMENT) takes the xml with attribute DOMVendor :="Xerces XML."
otherwise shows "invalid charector in line number x"

How I can set the DOMVendor :="Xerces XML" for  IXMLdocument?
0
Eddie ShipmanAll-around developerCommented:
With IXMLDOMDocument, you don't use a "vendor" It is Microsoft only.
Is TSL2FileStream loading the file into a TStringList before saving to a FileStream?
I don't understand what the need for that is, please explain.

Here's how you create and load and IXMLDOMDocument:


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, COMObj, msxml, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    oXMLDoc: IXMLDOMDocument;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  ssXML: TStringStream;
  //FS: TSL2FileStream;
  fsXML: TFileStream;
begin
  oXMLDoc        := CreateOleObject('MSXML2.DOMDocument.3.0') as IXMLDOMDocument;
  // FS             := TSL2FileStream.Create(XMLfile,fmShareDenyNone);
  // Here, I'm moving the XML from a FileStream to a StringStream.
  // It preserves the extended characters..
  ssXML := TStringStream.Create('');
  fsXML := TFileStream.Create('g:\Eddie\gamedata.XML', fmShareDenyNone);
  fsXML.Position := 0;
  ssXML.CopyFrom(fsXML, fsXML.Size);
  ssXML.Position := 0;
  try
    oXMLDoc.LoadXML(ssXML.DataString);
    // You work with the nodes a little different than with TXMLDOcument
    // If you need to know how to do certain things,with the nodes, just ask.
    Memo1.Lines.Text := oXMLDoc.xml;
    // Verify that it shows in the Memo...Yes it does!
    Memo1.Lines.SaveToFile('G:\Eddie\NameofFile.XML');
    // Verify that the character is still there in the XML...Yes it is!
  finally
    oXMLDoc  := nil;
    ssXML.Free;
    fsXML.Free;
  end;
end;

end.

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
udhnaAuthor Commented:
Hi Eddie,
Thanks a lot.
This is the solution.

Thanks to EE too.

Regards,
Vijesh V.Nair
0
udhnaAuthor Commented:
Eddie,
do me a Favour,
I want to find a Particular node , get all its childNodes and their data .
Plz  send me samples.

Regards,
Vijesh V.Nair
0
Eddie ShipmanAll-around developerCommented:
Here is some code I wrote several years ago to parse a feed from YouTube. It downloads the XML and then parses it into a ListView. This particular XML does not have attributes, or at least we aren't parsing any, so if you have the need to get the values of any attributes, let me know.

To see the XML that is used in the example below, use this URL:
http://gdata.youtube.com/feeds/api/videos?q=animation

procedure TForm1.Button1Click(Sender: TObject);
var
  tmp:            String;
  oXMLDoc:        IXMLDOMDocument;
  oNode:          IXMLDOMNode;
  oTitleNode:     IXMLDOMNode;
  oContentNode:   IXMLDOMNode;
  oAuthorNode:    IXMLDOMNode;
  oThumbnailNode: IXMLDOMNode;
  oEntryList:     IXMLDOMNodeList;
  oGroupList:     IXMLDOMNodeList;
  i:              Integer;
  item:           TListItem;
begin
  oXMLDoc := CreateOleObject('MSXML2.DOMDocument.3.0') as IXMLDOMDocument;
  try
    tmp := idHTTP1.Get('http://gdata.youtube.com/feeds/api/videos?q=animation');
    oXMLDoc.LoadXML(tmp);
    if oXMLDoc.childNodes.length > 0 then
    begin
      // There was data returned.
      oEntryList := oXMLDoc.selectNodes('/feed/entry');
      if oEntryList.length > 0 then
      begin
        for i := 0 to oEntryList.length-1 do
        begin
          item := ListView1.Items.Add;
          oNode := oEntryList.item[i];
          oGroupList := oNode.selectNodes('media:group');
          if oGroupList.length > 0 then
          begin
            oNode := oGroupList.item[0];
            if oNode <> nil then
            begin
              if oNode.childNodes.item[0].nodeName = 'media:title' then
                item.Caption := oNode.childNodes.item[0].text;
              if oNode.childNodes.item[1].nodeName = 'media:description' then
                item.SubItems.Add(oNode.childNodes.item[1].text);
              if oNode.childNodes.item[5].nodeName = 'media:content' then
                item.SubItems.Add(oNode.childNodes.item[5].attributes.item[0].Text);
              if oNode.childNodes.item[8].nodeName = 'media:thumbnail' then
                item.SubItems.Add(oNode.childNodes.item[8].attributes.item[0].Text);
            end;
          end;
        end;
      end;
    end;
  finally
    oXMLDoc := nil;
  end;
end;

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.