Re: document class
On 26 Sep., 04:12, Joseph M. Newcomer <newco...@flounder.com> wrote:
See below...
On Fri, 24 Sep 2010 13:44:00 -0700 (PDT), mfc <mfcp...@googlemail.com> wrote:
According to the CXML file class: at the beginning (in the
OnNewDocument method) I will call the xml class method to load the
specific xml file and load all the values / node values from the xml
file into a CStringList; after that I release the xml file.
****
What I did was load an XML file. Then I could call on methods to extract information from
the XML file. So, for example, if my display class had some characteristic such as
brightness, my CDisplay class knew how to query the XML file to locate the background
color. In my case, I did something like
int brightness = CDisplay.GetBrightness();
and the CDisplay knew it was part of the display.brightness feature, because the
implementation of CDisplay knew it was in myxmlfile.display.brightness, and that was the
only place that knew it, so it would ask for
CString brightness = XML.GetBrightness(_T("myxmlfile.display.brightness"));
int bright = _ttoi(brightness);
return bright;
along with some error checking to see that what came back was a numeric string and not
some nonsense. And if the value was not found, I would return a default value, say, 100.
joe
****
According to your xml file <display::brightness disabled="true"
level="50"/> - how will you get the information disabled="true" from
the xml file with your call CString brightness =
XML.GetBrightness(_T("myxmlfile.display.brightness"));?
****
I don't see how it makes sense. I used a concept of XMLNode and an XMLNode had various
fields, such as properties ("disabled") and text ("50"). I did not use a single
CStringList anywhere in my implementation.
Ultimately, I stored the named attributes in a std::map. But nobody outside the
implementaiton of XMLNode knew that.
****
In this case, a std::map makes much more sense.
According to this line <display::brightness disabled="true" level="50"/
:
std:map (will include the following)
<brightness><50>
<disbrightness><true>
Then if the http socket class say: I need the ip addr (Postmessage
which includes the node name) -> I will take a look into the CMap
searching for the key (name of the node which holds the value and the
attributes) -> add all these information in the correct order into a
CStringlist or CStringArray and return this list to the http socket
class....
****
As so as you say "correct order" my bogometer redlines. Why should order matter in the
slightest? Why should it even be a concept that enters the discussion?
****
I know what you are thinking about that!? it`s really difficult and
not simple.... The key is that the http socket class as well as the
CNetworkDlg needs the value of e.g. the ip addr as well as the
behaviour of the ip addr (is it disabled or not) . The ip (which
represents a cedit field in the CNetworkDlg class) could be disabled
(if the user will use dhcp to get a ip addr) or the ip could be not
disabled (if the user will use a static ip configuration).
****
These would be different named properties.
****
You mean different named properties in the std:map where all node
information from the xml list will be stored?
<brightness><50>
<disbrightness><true>
If the http socket class will (now) get some values from the std:map
in the xml file class, I will send a PostMessage to the visible window
including the threadID as well as a CStringList which includes all key
names of the std::map. I will search for each specific CString value
from this list in the std::map and will return another CStringList to
the http socket server including all values (instead of the keys).
void VisibleWindow::OnGetNewHttpRequest(wparam, lparam)
{
CStringList *slist = (CStringList *)wparam;
doc->GetData(slist);
::PostThreadMessage(UWM_SEND_BACK_TO_HTTP, slist, 0);
}
void MyDocClass::GetData(CStringList *slist)
{
POSITION pos = slist->GetHeadPosition;
while(pos)
{
CString value;
value = XML.GetValue(slist->GetAt(pos));
slist->SetAt(pos, value)
(void)slist->GetNext(pos);
}
}
This small example should only show what I mean by the text before. I
think it is much simpler;
How did you handle your xml file? loading the file, parsing the file
and generating a Cmap, cstringlist containing all the items from the
xmlfile? Or do you always release and reopen the xml file if the
application need some information from the xml file?
****
Loading and parsing the file, because I assumed code page 1252 (ISO-Latin-1 ANSI subset,
although all the code is Unicode), took me about six hours to code. It was actually
pretty trivial. I think the problem is that by forcing this notion of "correct order" you
have needlessly complicated a fundamentally simple task of dealing with name-value pairs.
Stop thinking in terms of string lists or string arrays and think exclusively in terms of
name-value pairs, and the whole thing falls apart into somthing quite trivial.
I have a subset parser I can send out which only handles attributes within nodes but not
text. So I would have
<display::brightness disabled="true" level="50"/>
as the representation used.
I need to make some extensions to this before I write it up for release on my site, but
I'm using it as a programming example, so in its current form, I have the rights to
release it.
joe
****
thats sounds interesting. Please give me a sign if this article is
available on your site.
best regards
Hans