f



Text to XML Problem

Hel'o All,
         Currently I am working with a application which involves,
writing text on windows, I am capable of writing text on windows but I
have to save it as an XML document,How to proceed for the same ,Can ne
one help me in achiving the desire task........



ne help appritiated........




Regards,


Paul..........
0
savita
3/17/2005 12:32:54 PM
comp.os.programmer.win32 14522 articles. 0 followers. Post Follow

6 Replies
488 Views

Similar Articles

[PageSpeed] 25

U can use MSXML.dll for creating and saving XML documents.

0
Shaji
3/17/2005 2:14:56 PM
"Paul Allen" <savita.trivedi@gmail.com> wrote in message
news:903ad890.0503170432.5594b517@posting.google.com...
> Hel'o All,
>          Currently I am working with a application which involves,
> writing text on windows, I am capable of writing text on windows but I
> have to save it as an XML document,How to proceed for the same ,Can ne
> one help me in achiving the desire task........

If you have the data in memory in XML format just save it. :)
If not then either interpret your internal data structures and store the
elements in the appropriate XML tags and attributes.

In what format do you now store the data that you use to update the
screen in WM_PAINT? What is the source and source format?

If you currently only display what you get directly without bathering
with WM_PAINT then you should redesign your code to store the
data off-screen and only draw it when needed.

Finally, if you need XML output then it would pay off structuring the
data in similar ways in memory. So  if your output should be
<document>
    <element type="rectangle">22,33,244,22</element><newline/>
    <element type="text" font="Arial" fontsize="12">This is text</element>
</document
then you would keep it in memory as a list of element structures
with needed meta data, pointer(s) to data and pointers to next element...

- Sten



0
Sten
3/17/2005 2:18:53 PM
"Sten Westerback" <sten.westerback@NO_SPAMnokia.com> wrote in message news:<hlg_d.40852$k4.798276@news1.nokia.com>...
> "Paul Allen" <savita.trivedi@gmail.com> wrote in message
> news:903ad890.0503170432.5594b517@posting.google.com...
> > Hel'o All,
> >          Currently I am working with a application which involves,
> > writing text on windows, I am capable of writing text on windows but I
> > have to save it as an XML document,How to proceed for the same ,Can ne
> > one help me in achiving the desire task........
> 
> If you have the data in memory in XML format just save it. :)
> If not then either interpret your internal data structures and store the
> elements in the appropriate XML tags and attributes.
> 
> In what format do you now store the data that you use to update the
> screen in WM_PAINT? What is the source and source format?
> 
> If you currently only display what you get directly without bathering
> with WM_PAINT then you should redesign your code to store the
> data off-screen and only draw it when needed.
> 
> Finally, if you need XML output then it would pay off structuring the
> data in similar ways in memory. So  if your output should be
> <document>
>     <element type="rectangle">22,33,244,22</element><newline/>
>     <element type="text" font="Arial" fontsize="12">This is text</element>
> </document
> then you would keep it in memory as a list of element structures
> with needed meta data, pointer(s) to data and pointers to next element...
> 
> - Sten


I think I am not very clear to my point, Well I don't know how to
process for Saving and Reteriving Text as an XML Document from some
text editor, Either I have to design some data structure, or ne other
way if any body knws, Plz tell me the algorithm or the process of how
to achive the desired task.


Regards,
0
savita
3/19/2005 6:28:08 AM
"Paul Allen" <savita.trivedi@gmail.com> wrote in message
news:903ad890.0503182228.178fa382@posting.google.com...
> "Sten Westerback" <sten.westerback@NO_SPAMnokia.com> wrote in message
news:<hlg_d.40852$k4.798276@news1.nokia.com>...
> > "Paul Allen" <savita.trivedi@gmail.com> wrote in message
> > news:903ad890.0503170432.5594b517@posting.google.com...
> > > Hel'o All,
> > >          Currently I am working with a application which involves,
> > > writing text on windows, I am capable of writing text on windows but I
> > > have to save it as an XML document,How to proceed for the same ,Can ne
> > > one help me in achiving the desire task........
> >
> > If you have the data in memory in XML format just save it. :)
> > If not then either interpret your internal data structures and store the
> > elements in the appropriate XML tags and attributes.
> >
> > In what format do you now store the data that you use to update the
> > screen in WM_PAINT? What is the source and source format?
> >
> > If you currently only display what you get directly without bathering
> > with WM_PAINT then you should redesign your code to store the
> > data off-screen and only draw it when needed.
> >
> > Finally, if you need XML output then it would pay off structuring the
> > data in similar ways in memory. So  if your output should be
> > <document>
> >     <element type="rectangle">22,33,244,22</element><newline/>
> >     <element type="text" font="Arial" fontsize="12">This is
text</element>
> > </document
> > then you would keep it in memory as a list of element structures
> > with needed meta data, pointer(s) to data and pointers to next
element...
> >
> > - Sten
>
>
> I think I am not very clear to my point, Well I don't know how to
> process for Saving and Reteriving Text as an XML Document from some
> text editor, Either I have to design some data structure, or ne other
> way if any body knws, Plz tell me the algorithm or the process of how
> to achive the desired task.

I still think you are extremly unclear.. ;)

Firstly you haven't specified if you are talking about some XML format
you have already defined or that someone else has defined. Or are you
about to do that yourself?
Also, is the "Text" you want to store in XML file formatted in any way?

The most simple answer to your question so far is something like
1. get HWND of Edit box control in a dialog box or on a normal window
2. send WM_GETTEXT to read the text in the control to a szValue buffer
3. sprintf(sz, "%s\r\n<document><text>%s</text></document>",
        szHeader, szValue);
4. h=CreateFile(....) ; WriteFile(h, ... sz ... )
5. CloseHandle(h);

and the other way the other way around... :)

To confirm 100 % to XML specs you would have to convert the characters
to UTC-8 format. Here is a routine for that for ANSI-mode:

int Lib_iAnsiToUTF8(char *p_szIn, char *p_szOut, int nOutBuffSize)
{
 WCHAR *p_wsz; DWORD dw, dwO;  int  i;

 // Ansi -> UNICODE
 dw=strlen(p_szIn)+1; dwO=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
p_szIn, dw, NULL, 0);
 p_wsz=malloc(dwO * sizeof(WCHAR));
 dwO=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, p_szIn, dw, p_wsz, dwO);
 // UNICODE -> UTF8
 i=WideCharToMultiByte(CP_UTF8, 0, p_wsz, dwO, p_szOut, nOutBuffSize, NULL,
NULL);
 free(p_wsz); return i;
}

If you work in UNICODE mode the you can skip the first part of the function.
The basic XML header you can find in most .xml files but you should add the
things you need such as .xsl path etc.

- Sten



0
Sten
3/21/2005 12:20:44 PM
"Sten Westerback" <sten.westerback@NO_SPAMnokia.com> wrote in message news:<w_y%d.41100$k4.802657@news1.nokia.com>...
> "Paul Allen" <savita.trivedi@gmail.com> wrote in message
> news:903ad890.0503182228.178fa382@posting.google.com...
> > "Sten Westerback" <sten.westerback@NO_SPAMnokia.com> wrote in message
> news:<hlg_d.40852$k4.798276@news1.nokia.com>...
> > > "Paul Allen" <savita.trivedi@gmail.com> wrote in message
> > > news:903ad890.0503170432.5594b517@posting.google.com...
> > > > Hel'o All,
> > > >          Currently I am working with a application which involves,
> > > > writing text on windows, I am capable of writing text on windows but I
> > > > have to save it as an XML document,How to proceed for the same ,Can ne
> > > > one help me in achiving the desire task........
> > >
> > > If you have the data in memory in XML format just save it. :)
> > > If not then either interpret your internal data structures and store the
> > > elements in the appropriate XML tags and attributes.
> > >
> > > In what format do you now store the data that you use to update the
> > > screen in WM_PAINT? What is the source and source format?
> > >
> > > If you currently only display what you get directly without bathering
> > > with WM_PAINT then you should redesign your code to store the
> > > data off-screen and only draw it when needed.
> > >
> > > Finally, if you need XML output then it would pay off structuring the
> > > data in similar ways in memory. So  if your output should be
> > > <document>
> > >     <element type="rectangle">22,33,244,22</element><newline/>
> > >     <element type="text" font="Arial" fontsize="12">This is
> text</element>
> > > </document
> > > then you would keep it in memory as a list of element structures
> > > with needed meta data, pointer(s) to data and pointers to next
> element...
> > >
> > > - Sten
> >
> >
> > I think I am not very clear to my point, Well I don't know how to
> > process for Saving and Reteriving Text as an XML Document from some
> > text editor, Either I have to design some data structure, or ne other
> > way if any body knws, Plz tell me the algorithm or the process of how
> > to achive the desired task.
> 
> I still think you are extremly unclear.. ;)
> 
> Firstly you haven't specified if you are talking about some XML format
> you have already defined or that someone else has defined. Or are you
> about to do that yourself?
> Also, is the "Text" you want to store in XML file formatted in any way?
> 
> The most simple answer to your question so far is something like
> 1. get HWND of Edit box control in a dialog box or on a normal window
> 2. send WM_GETTEXT to read the text in the control to a szValue buffer
> 3. sprintf(sz, "%s\r\n<document><text>%s</text></document>",
>         szHeader, szValue);
> 4. h=CreateFile(....) ; WriteFile(h, ... sz ... )
> 5. CloseHandle(h);
> 
> and the other way the other way around... :)
> 
> To confirm 100 % to XML specs you would have to convert the characters
> to UTC-8 format. Here is a routine for that for ANSI-mode:
> 
> int Lib_iAnsiToUTF8(char *p_szIn, char *p_szOut, int nOutBuffSize)
> {
>  WCHAR *p_wsz; DWORD dw, dwO;  int  i;
> 
>  // Ansi -> UNICODE
>  dw=strlen(p_szIn)+1; dwO=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
> p_szIn, dw, NULL, 0);
>  p_wsz=malloc(dwO * sizeof(WCHAR));
>  dwO=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, p_szIn, dw, p_wsz, dwO);
>  // UNICODE -> UTF8
>  i=WideCharToMultiByte(CP_UTF8, 0, p_wsz, dwO, p_szOut, nOutBuffSize, NULL,
> NULL);
>  free(p_wsz); return i;
> }
> 
> If you work in UNICODE mode the you can skip the first part of the function.
> The basic XML header you can find in most .xml files but you should add the
> things you need such as .xsl path etc.
> 
> - Sten

Dear Sten,
         ThanX for your reply,well firstly i shud specify that I am
not using any of the common controls, as I am writing directly on the
window, Now second point is, When I click on the save from the menu,
It should get the text which is there on window and save that as an
XML Document, Now if i say open to retrieve it, It should retrieve as
XML document.

I am able to write on the window..... And Searching for the same....

Hope this clear the problem statement......


Regards......
0
savita
3/22/2005 6:02:23 AM
"Paul Allen" <savita.trivedi@gmail.com> wrote in message
news:903ad890.0503212202.49a71ca5@posting.google.com...
> "Sten Westerback" <sten.westerback@NO_SPAMnokia.com> wrote in message
news:<w_y%d.41100$k4.802657@news1.nokia.com>...
> > "Paul Allen" <savita.trivedi@gmail.com> wrote in message
> > news:903ad890.0503182228.178fa382@posting.google.com...
> > > "Sten Westerback" <sten.westerback@NO_SPAMnokia.com> wrote in message
> > news:<hlg_d.40852$k4.798276@news1.nokia.com>...
> > > > "Paul Allen" <savita.trivedi@gmail.com> wrote in message
> > > > news:903ad890.0503170432.5594b517@posting.google.com...
> > > > > Hel'o All,
> > > > >          Currently I am working with a application which involves,
> > > > > writing text on windows, I am capable of writing text on windows
but I
> > > > > have to save it as an XML document,How to proceed for the same
,Can ne
> > > > > one help me in achiving the desire task........
> > > >
> > > > If you have the data in memory in XML format just save it. :)
> > > > If not then either interpret your internal data structures and store
the
> > > > elements in the appropriate XML tags and attributes.
> > > >
> > > > In what format do you now store the data that you use to update the
> > > > screen in WM_PAINT? What is the source and source format?
> > > >
> > > > If you currently only display what you get directly without
bathering
> > > > with WM_PAINT then you should redesign your code to store the
> > > > data off-screen and only draw it when needed.
> > > >
> > > > Finally, if you need XML output then it would pay off structuring
the
> > > > data in similar ways in memory. So  if your output should be
> > > > <document>
> > > >     <element type="rectangle">22,33,244,22</element><newline/>
> > > >     <element type="text" font="Arial" fontsize="12">This is
> > text</element>
> > > > </document
> > > > then you would keep it in memory as a list of element structures
> > > > with needed meta data, pointer(s) to data and pointers to next
> > element...
> > > >
> > > > - Sten
> > >
> > >
> > > I think I am not very clear to my point, Well I don't know how to
> > > process for Saving and Reteriving Text as an XML Document from some
> > > text editor, Either I have to design some data structure, or ne other
> > > way if any body knws, Plz tell me the algorithm or the process of how
> > > to achive the desired task.
> >
> > I still think you are extremly unclear.. ;)
> >
> > Firstly you haven't specified if you are talking about some XML format
> > you have already defined or that someone else has defined. Or are you
> > about to do that yourself?
> > Also, is the "Text" you want to store in XML file formatted in any way?
> >
> > The most simple answer to your question so far is something like
> > 1. get HWND of Edit box control in a dialog box or on a normal window
> > 2. send WM_GETTEXT to read the text in the control to a szValue buffer
> > 3. sprintf(sz, "%s\r\n<document><text>%s</text></document>",
> >         szHeader, szValue);
> > 4. h=CreateFile(....) ; WriteFile(h, ... sz ... )
> > 5. CloseHandle(h);
> >
> > and the other way the other way around... :)
> >
> > To confirm 100 % to XML specs you would have to convert the characters
> > to UTC-8 format. Here is a routine for that for ANSI-mode:
> >
> > int Lib_iAnsiToUTF8(char *p_szIn, char *p_szOut, int nOutBuffSize)
> > {
> >  WCHAR *p_wsz; DWORD dw, dwO;  int  i;
> >
> >  // Ansi -> UNICODE
> >  dw=strlen(p_szIn)+1; dwO=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
> > p_szIn, dw, NULL, 0);
> >  p_wsz=malloc(dwO * sizeof(WCHAR));
> >  dwO=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, p_szIn, dw, p_wsz,
dwO);
> >  // UNICODE -> UTF8
> >  i=WideCharToMultiByte(CP_UTF8, 0, p_wsz, dwO, p_szOut, nOutBuffSize,
NULL,
> > NULL);
> >  free(p_wsz); return i;
> > }
> >
> > If you work in UNICODE mode the you can skip the first part of the
function.
> > The basic XML header you can find in most .xml files but you should add
the
> > things you need such as .xsl path etc.
> >
> > - Sten
>
> Dear Sten,
>          ThanX for your reply,well firstly i shud specify that I am
> not using any of the common controls, as I am writing directly on the
> window,

Ok, so what you want is a (freeware) OCR? Is there something that stops
you from storing the data also in text form in addition to the graphical
form?

In most cases that i can think of you would store data in memory structures
and draw (portions of it) when WM_PAINT is processed. In such cases
it doesn't matter if you use standard or common controls or a plain window
class of your own to display the data and let the user interact.

> Now second point is, When I click on the save from the menu,
> It should get the text which is there on window and save that as an
I though you said you don't have a window that stores the data. So
you have only a temporary graphical image of the text which will
disappear when another window is temporarily on top of your window.

> XML Document, Now if i say open to retrieve it, It should retrieve as
> XML document.
Graphical data is normally not suitable for XML unless you really want
to hex encode a bitmap and specify clues as to how the bitmap data
should be decoded and interpreted.

> I am able to write on the window.....
Why write yourself if all you write is text? You should consider using
an Rich Text editbox.

>And Searching for the same....
Searching for graphical pixels? Or do you mean you are able to keep
track of the HWND to the window (you get it from WndProc parameter
so no finding process would be involved).

> Hope this clear the problem statement......

Yeah... seems like you are using a bad design.... ;)

- Sten



0
Sten
3/22/2005 1:24:28 PM
Reply: