Writing string data in XML while Unicode build...

Hi

i am working in an application where i have to save text "string data"
in XML file. I am using VC++ 6 and current build is Unicode ("Unicode
configurations").

my code is ....

     CString constr2;
     CString str1 = "Country";

     constr2 = "CurrentSetting:"+str1;

     USES_CONVERSION;
    	
     char *p = T2A(constr2);

     outXml.write(p, str2); //parameters: (const char*, CString)


But the output in the XML file is "023423".


Before this while i am working with "MBCS", my code was

     CString constr2;
     CString str1 = "Country";

     constr2 = "CurrentSetting:"+str1;
     
     outXml.write(str1, str2);


this works fine and output text in the XML file was correct.

My question is why in Unicode configuration (as Unicode environment
does not accept CString as const char*, and i have managed it through
using unicode macro) does not work exactly.

could anybody please tell me any hints about this problem.

Thanks in Advance.

Mujtaba
0
tomujtaba (49)
12/10/2004 1:14:30 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
424 Views

Similar Articles

[PageSpeed] 47

a) I believe CString does not have cast to const char* operator in UNICODE,
for two reasons:
1) Developers must be aware that conversion is taking place and they should
try to avoid this.
outXml.write(p, str2) should have been defined as:
return_type write(LPCTSTR, const CString &)
LPCSTR translate to const _wchar * in _UNICODE is defined.
2) This would be to expensive to implement.

b) I believe write() method is defined in another module, that is built in
non-Unicode mode. That module expects to ASCII charaters in the CString's
buffer, but CString passed has a pointer to Unicode character buffer.

-- Vladimir Khvostov


because it is impossible to implement one.
In Unicode build, CString has a pointer to an internal buffer, that consist
of Unicode characters (_wchar_t). To return char * CString must allocate
buffer

"Mujtaba" <tomujtaba@hotmail.com> wrote in message
news:8f4f92aa.0412100514.1f223983@posting.google.com...
> Hi
>
> i am working in an application where i have to save text "string data"
> in XML file. I am using VC++ 6 and current build is Unicode ("Unicode
> configurations").
>
> my code is ....
>
>      CString constr2;
>      CString str1 = "Country";
>
>      constr2 = "CurrentSetting:"+str1;
>
>      USES_CONVERSION;
>
>      char *p = T2A(constr2);
>
>      outXml.write(p, str2); //parameters: (const char*, CString)
>
>
> But the output in the XML file is "023423".
>
>
> Before this while i am working with "MBCS", my code was
>
>      CString constr2;
>      CString str1 = "Country";
>
>      constr2 = "CurrentSetting:"+str1;
>
>      outXml.write(str1, str2);
>
>
> this works fine and output text in the XML file was correct.
>
> My question is why in Unicode configuration (as Unicode environment
> does not accept CString as const char*, and i have managed it through
> using unicode macro) does not work exactly.
>
> could anybody please tell me any hints about this problem.
>
> Thanks in Advance.
>
> Mujtaba


0
12/10/2004 5:53:07 PM
> I am using VC++ 6 and current build is Unicode ("Unicode
> configurations").
....

> my code is ....
>      CString constr2;
>      CString str1 = "Country";
I don't think the application is Unicode, because the code abouve would not 
compile. Should be L"Country" or _T("Country").
If it really is the way you quoted it and it compiles, it is not an Unicode
application.
Did you defined both UNICODE and _UNICODE ?

-- 
Mihai
-------------------------
Replace _year_ with _ to get the real email
0
12/11/2004 6:55:02 AM
The code would compile, but it would be suboptimal because of invoking 
ANSI->UNICODE conversion.
There is CString constructor and assignment operation accepting YCHAR (The 
Other Char type).

"Mihai N." <nmihai_year_2000@yahoo.com> wrote in message 
news:Xns95BBE927A383BMihaiN@207.46.248.16...
>> I am using VC++ 6 and current build is Unicode ("Unicode
>> configurations").
> ...
>
>> my code is ....
>>      CString constr2;
>>      CString str1 = "Country";
> I don't think the application is Unicode, because the code abouve would 
> not
> compile. Should be L"Country" or _T("Country").
> If it really is the way you quoted it and it compiles, it is not an 
> Unicode
> application.
> Did you defined both UNICODE and _UNICODE ?
>
> -- 
> Mihai
> -------------------------
> Replace _year_ with _ to get the real email 


0
alegr (1131)
12/11/2004 3:35:36 PM
> The code would compile, but it would be suboptimal because of invoking 
> ANSI->UNICODE conversion.
> There is CString constructor and assignment operation accepting YCHAR (The 
> Other Char type).
Oups. I am using 2003 for too long :-)
With Dev.Studio 6 works, with Dev.Studio 2003 it does not.

-- 
Mihai
-------------------------
Replace _year_ with _ to get the real email
0
12/12/2004 9:35:23 AM
Reply:

Similar Artilces:

Seeing Two instances of the Data File in the TRee!
I am sorry for the obscure Subject line, but I can't think of a way to describe this. I am using Outlook with regular Internet Email. I have it set up with the standard one Data File. When I go to the Data Files page, there is only one file in use. But.. In the Tree on the Left (in Office 2003) I see 2 personal Folders (of the Data File) and they are exactly the same thing, when I get new email, both inboxes receive the file. Also, when I go to the Email Accounts page, and I want to choose which Data File to direct the emails to, it shows 2 options, both having the same name (Duh, ...

xml receipt modification
is there a way to have a receipt print the long description on a receipt but only if the the customer is paying "Price A", and not have it print for all other customers. Please help. Thank You Victor Hi Victor, If you are interested we can offer a custom solution. Please drop a email. Regards, Manick manick.m@hotmail.com "Victor" wrote: > is there a way to have a receipt print the long description on a receipt but > only if the the customer is paying "Price A", and not have it print for all > other customers. > Please help. > Thank You >...

how do i see which data matches between two worksheets?
I need to compare a very long worksheet (W1) to a shorter worksheet (W2) to see if any of the files listed on W1 are on W2. I then need to copy the matching rows from W2 to a new worksheet. Hi, look CPearson web http://www.cpearson.com/excel/ListFunctions.aspx second title Extracting Elements Common To Two Lists "Judy" wrote: > I need to compare a very long worksheet (W1) to a shorter worksheet (W2) to > see if any of the files listed on W1 are on W2. I then need to copy the > matching rows from W2 to a new worksheet. ...

Template Wizard with Data Tracking #7
Where do I get the Template Wizard with Data Tracking for Office 2003? I found one for Office 2002 and I tried it, but is doesn't work. ...

Can somebody write a sample?
Hello, can somebody write a sample to understand better the code in http://codetools.com/miscctrl/cntgroup.asp Regards, Rainer ...

Automatic data collection in Manufacturing
How does this work? I see where you can designate a workstation as an ADC processor, but where do you setup to let your bar code scanner enter information. What exactly is the setup on this? Anyone? "Dnelson" wrote: > How does this work? I see where you can designate a workstation as an ADC > processor, but where do you setup to let your bar code scanner enter > information. What exactly is the setup on this? If you figure the answer, do post. I will be interested in knowing this too. Scott "Dnelson" wrote: > How does this work? I see where you ca...

XML file width
I'm converting a 1MB bitmap file into base64 encoding..and saving into an xml file. the xml file and everything works perfectly...except when i open the xml file in a viewer I get errors becuase the file is written to just one line with no coluumn width etc? how can I ensure the xml writer in vb.net spits out beautifully formatted xml code like the access 2003 etc..?? with my 1MB <image> tag spread over thousands of lines 80 chars wide instead of just 1 long line that crashes any text editor...? cheers Simon Simon wrote: > I'm converting a 1MB bitmap file into b...

Excel 2007 crashes after viewing property sheet in Data Connection
I have been using Excel 2007 to import comma delimited text (csv) files stored on my local hard disk into my personal finance spreadsheet. The Data>Get External Data>From Text wizard works fine and have had no trouble using the Refresh function. The problem comes from accessing a Connection Properties Box from the Data>Connections Box. If I select OK after viewing the Properties Box, Excel crashes, restarts, and offers to let me continue working on a repaired worksheet. This behavior occurs even when no changes are made in the Properties Box. If I select Cancel, Excel exits the...

How do I plot Excel data on a floorplan?
I'm trying to find a way to plot data from an Excel worksheet on a floorplan diagram. The data reflects room assignments for a hospital, so some data stays the same for days while other data changes on a twice a day basis. I want to enable someone to be able to enter the data on the worksheet and have excel output the names, etc in the proper room assignments on the floorplan automatically. The users could then print this floorplan to locate the assignments more easily. I can either scan a hardcopy of the floorplan, or I have access to Visio so I could also quickly construct a d...

XML DTD Question
Here is my original xml structure. I want to add another child node called hyperlinks to the parent graphic. How would I modify this DTD to reflect this new child being added. Thank You for any help toward this end! <graphics> <graphic> <tag> <parameter/> <parameter/> <parameter/> </tag> <tag> <parameter/> </tag> </graphic> </graphics> New Structure: <graphics> <graphic> <tag> ...

XML-Control .NET
Hallo NG, ich habe folgende Anforderung: Ein XML-Dokument soll in einen Editor eingelesen werden, also in ein Control das XML als Baum darstellt, die Node-Values und Attribute sollen editierbar sein. Kennt jemand da ein geeignetes Control f=FCr (kann auch Geld kosten). Dank und Gru=DF, Matthias Matthias wrote: > ich habe folgende Anforderung: Ein XML-Dokument soll in einen Editor > eingelesen werden, also in ein Control das XML als Baum darstellt, die > Node-Values und Attribute sollen editierbar sein. Kennt jemand da ein > geeignetes Control f�r (kann auch Geld kosten). I d...

Sorting Data Employee name time
I have a worksheet of data (Employee names and times from job sheets) which i need to sort by employee name and then totalise times to find total hours worked for the job. There name may apear several times or not at all. I need a total for each person then to be written to the database sheet through the database template add in. Hi for this I would use a pivot table. <See: http://www.cpearson.com/excel/pivots.htm http://peltiertech.com/Excel/Pivots/pivotstart.htm http://www.contextures.com/xlPivot02.html http://www.ozgrid.com/Excel/excel-pivot-tables.htm -- Regards Frank Kabel Frank...

Help help, combining limited data
HI guys I was wondering if you could help me with writing a formula that meets this criteria... 1. I need to combine Text in column A to Column B (=A1&B1) 2. BUT I only need the first letter of coumn A to combine with the rest of column B 3. Columb C needs to be <= 10 chracters Goal : Text in Column C for row 1 = sAAABBBCCCD Text in Column C for row 2 = gBBBBBBCCCD If it doesnt have to be all in one formual, I mean I can combine A and B and then do a formula for C, i just need the results to be the first letter of the A column combined with <= 9 digits of the Column B ----------...

pasting chart getting source data from new location
I have a spreadsheet and chart of which I need several instances. When I copy and paste the sheet, the source data for the new chart is pointing to the original spreadsheet. My goal is to have a new sheet and chart that is independent from the original, however works the same way. New data entered into the new spredsheet will display on the the new graph. This functionality is by design but you can easily change the source of any chart. To do so, first click on the outside edge of the chart. Next, right-click on your mouse and select "source data". Finally, in the source...

DOCTYPE with Xml Serialization
I have a class that serialize using the XmlSerializer. I am using several attributes for class members to control serialization process. One thing I cannot figure out how to do is how to add DOCTYPE attribute to the file. This XML file must use the doctype that refers to the DTD rather than an XSD. Could someone point out how to accomplish that using the attributes or by some other means? Thanks! Hi Vlad, Welcome to MSDN newsgroup. From your description, when you use the .NET XmlSerizliation to serizliaze some class instances out to xml stream, you want to also expose the DocType for ...

Change source data of a pivot chart
In Excel 2007 can you change the source data of a pivot chart I have multiple charts and tables which I want to copy but the copied charts still refer to the original pivot table I have limited practice with this, but I think if you copy the sheet with the pivot table and chart to a new workbook, the links travel with the copied pivot table, not the original. You can then move the sheet into the original workbook. - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions Peltier Technical Services, Inc. - http://PeltierTech.com _______ "MRIreland" <MRI...

Equation connecting two data quantities
Hi, I have data like this: in an excel sheet. Q C Equation 1 2 3 4 ; 22 44 34 55 88; ? Is there anyway that I can get an equation connecting these two quantities Q and C, (data arranged in this manner only, as I have lot of data where in I cant put that in two separate rows because of some constraints) Can I get a formula connecting these two variables in the quation cell. Thanks Assuming that the data fits a linear plot (and that you have a typo): read help on SLOPE and INTERCEPT If not linear; find how to draw a trendline; find trendline...

Excel 2002 cannot copy data from website to excel
I have data in a website that looks like the following US 04872 - CASS CITY CASMI CTR 2 US 04881 - FLINT-SOUTH 4881 CTR 2 US 04885 - MOUNT PLEASANT MTPMI CTR 2 In previous versions of excel, when I copy this data it would put US in column 04872 in column - in column CASS CITY in column 4 and so on The problem is now when I copy this data and try to paste it into Excel 2002 I receive the following error "Microsoft Excel cannot paste data" What should I do? - Paste Special as text is not a good option cause it doesn't...

missed data
The following Vlookup formula has this link to another workbook supposedly in the same folder where the workbook is placed, but there is no such a file with this name, where is this DATA.xls stored =BUSCARV($B76;'C:\Documents and Settings\rjimenez\Mis documentos\[DATA.xls]Recursos'!$B$2:$E$1501;2;FALSO) thanks for your help -- rjl ------------------------------------------------------------------------ rjl's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=30117 View this thread: http://www.excelforum.com/showthread.php?threadid=498475 rjl schreef: &...

Letter Writing assitant to be used with Prospects
Would like to see Letter Writing Assitant to be extended to be used with Prospects. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/Community/NewsGroups/dgbrowser/en-us/default.mspx?mid=73b8a531-e5c3-4d8b-91ae-5b1758b9f1a5&...

double clicking and draging a column in a chart to chg data
in Excel 2003, double clicking on a column in a chart and then dragging the column up or down would change the data in a table upon which the chart depended. How does one do this in excel 2007? Tom Hi, That feature has been removed in 2007, there is no way to do it. If this helps, click the Yes button. -- Thanks, Shane Devenshire "Tom of inns" wrote: > in Excel 2003, double clicking on a column in a chart and then dragging the > column up or down would change the data in a table upon which the chart > depended. > > How does one do this in excel 2007? &g...

Various XML streaming problems
I'm trying to process a MemoryStream of XML data, which at any point in time may have incomplete fragments (because data arrives from a socket). If I process data until XmlTextReader.Read() returns false, fills it with more data, and reverses the position of the underlying MemoryStream, the XmlTextReader immediately stops working. I apparently have to re-create the XmlTextReader instance when I make changes to the MemoryStream. The XmlTextReader constructor apparently advances the position of the MemoryStream to the end even before I've tried to Read(), which makes it hard to know ex...

how can i transfer data from one sheet to another without blank li
Dear All I have extracted data from a system to a sheet including blank lines between the data. Any idea of how i can transfer the data from one sheet to another without any blank lines, in order to do my job using excel functions? Thanks in advance If you mean blank rows why dont you just sort the data? In case you need to retain the order (you can use a temporary column); insert an additional column say A. Number 1,2,....till the end in cells a1,a2 ...... Sort col B. Delete the blank rows..and then sort by ColA...Remove ColA -- Jacob (MVP - Excel) "Manos&q...

Leading and trailing spaces trimmed with SQL XML
Hi, I am inserting data into a table using xml bulk insert. One of the field is of string type and contains data with leading and trailing spaces. But on insert the spaces automatically trimmed off. Can you please tell me how to avoid this trimming of spaces, as i have to insert data using xml. EXEC sp_xml_preparedocument @hDoc OUTPUT, @InsertLines INSERT INTO tblLine WITH (TABLOCKX) ([Text]) SELECT [Text] FROM OPENXML (@hDoc, '/Lines/Line', 1) WITH ([Text] nvarchar(max)) EXEC sp_xml_removedocument @hDoc Thank you Frank bad_clone (bad_clone@hotmail.com) writes: ...

string.Replace((char)146, (char)39) does not work?
Can anyone tell me why this code doesn't work? // Key = Char to find, Value = Char to replace. Hashtable specialChars = new Hashtable(); specialChars.Add((char)146, (char)39); foreach (DictionaryEntry entry in specialChars) { this.label.Text = this.label.Text.Replace(Convert.ToChar(entry.Key), Convert.ToChar(entry.Value)); } mohaaron wrote: > Can anyone tell me why this code doesn't work? Because C# strings are UTF-16, not some random extended ASCII encoding you've chosen to use. Hint: if you are casting numeric literals to System.Char, your code is pro...