|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Background
This project and article started when trying to write a sample
application that used the new What Should I Get From This
It was my goal that you would get some useful information about using
the .NET Namespaces Sample
The .NET Namespaces application is pretty straightforward. It loads
an XML file called ![]() Figure 1: Output from DotNetNamespace.exe Namespaces.XMLBelow is the layout of the Namespaces XML file and from which the application drives it implementation. <?xml version="1.0"?> <Namespaces> <Namespace Name="System"> <Namespace Name="CodeDOM"> <Namespace Name="Compiler"/> </Namespace> <Namespace Name="Collections"> <Namespace Name="Bases"/> </Namespace> <Namespace Name="ComponentModel"> <Namespace Name="Design"> <Namespace Name="CodeModel"/> </Namespace> </Namespace> <!-- ... SNIPPED ... --> <Namespace Name="Core">[...]</Namespace> <!-- ... SNIPPED ... --> </Namespace> </Namespaces> DotNetNamespace.CPP
I thought I would take a paragraph and describe some of the
Below we can see that we are using the LoadAndParse().
// build path to tip of the day xml file CAtlStringW strFileName("Namespaces.xml"); VARIANT_BOOL vbLoaded = VARIANT_FALSE; // Load the XML file. hr = ptrNamespacesXML->load(_variant_t(strFileName), &vbLoaded); if (SUCCEEDED(hr) && vbLoaded == VARIANT_TRUE) { // ... Code Snipped } else { wcout << L"Problem: Unable to load, " << strFileName.GetString() << endl; // *** PCXSTR is undefined so must use GetString in Beta1 //wcout << L"Problem: Unable to load, " << (PCXSTR)strFileName << endl; }
Next we show some of the new methods that you can use to help build strings up more easily.
By using the DisplayNamespaces(), taken from just after getting the Name attribute from the Namespace node.
// ... Code Snipped BSTR bstrName = NULL; hr = ptrName->get_text(&bstrName); if (SUCCEEDED(hr) && bstrName) { if (strPath.GetLength() == 0) { strPath = bstrName; } else { strPath.AppendFormat(L".%s", bstrName); } SysFreeString(bstrName), bstrName = NULL; wcout << strPath.GetString() << endl; } // ... Code Snipped
If we wanted to we could have used the // ... Code Snipped BSTR bstrName = NULL; hr = ptrName->get_text(&bstrName); if (SUCCEEDED(hr) && bstrName) { if (strPath.GetLength() == 0) { strPath = bstrName; } else { strPath.AppendFormat(L".%s", bstrName); } SysFreeString(bstrName), bstrName = NULL; strPath.MakeUpper(); // "System.CodeDOM" --> "SYSTEM.CODEDOM" wcout << strPath.GetString() << endl; } // ... Code Snipped
We could have also gotten tricky and called the Excercises Left For The Reader
While The Namespaces.xml file is started, it is far from complete.
If you want to take it farther, you could build out the Namespaces.XML
file to include the other additional namespaces and classes contained
within the namespaces. You could also build out the tree to show the
number of children contained within each level of a namespace. Building
this into the existing applicaiton will develop your experience with the
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||