Microsoft Visual C++ .NET Professional Projects - Premier Press
.pdf
XML WITH VC++.NET Chapter 28 831
{
reader->Read();
//The first 10 characters give you the date, so discard the rest. lvi->SubItems->Add((reader->Value)->Substring(0,10)) ;
}
}
else
{
if(reader->NodeType==XmlNodeType::Text)
{
lvi->SubItems->Add(reader->Value);
}
}
}
}
catch(Exception *e)
{
Console::WriteLine(e->Message);
}
reader->Close();
}
Now the data in the XML file can be parsed and displayed in the ListView. All that is left now is to add the functionality for the event handler for the button labeled Generate Report.
The method will make use of another fundamental .NET XML class, XslTransform, found in the System::XML::Xsl namespace. This class is used to transform an XML document using an XSL stylesheet.
The steps involved are simple. First create an object of the type XslTransform, and then load the XSL file using the XslTransform::Load method, which accepts the URL of an XSL file as a parameter. Transform it by calling the form::Transform method. This method accepts two parameters, the name of the XML file to be transformed and the name of the file to store the transformation in.
XML WITH VC++.NET Chapter 28 833
<tr>
<td><xsl:value-of select=”ReqDate”/> </td>
<td><xsl:value-of select=”ReqLocation”/> </td>
<td><xsl:value-of select=”Category”/> </td>
<td><xsl:value-of select=”Detail”/> </td>
<td><xsl:value-of select=”CustomerNo”/> </td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Build the application and copy the HTM.xsl file, created in the preceding section, into the folder containing the application’s executable. Execute the application. First enter the name of the technical support person as it appears in the database and click on the Get Data button. Once the XML file has been created and the ListView is populated with the data, the Generate Report button should become enabled. Click on the Generate Report button to generate an HTML file. Open the generated HTML file and verify its contents with the contents of the database.
Summary
In this chapter, you created a Managed C++ application that uses the .NET classes in the Xml namespace to create and manipulate XML documents and data. You also learned how the .NET Framework’s XML classes simplify XML access and manipulation. While providing faster, lighter classes for XML reading and writing, the .NET Framework also provides classes that allow you to access XML documents using the traditional DOM API.
This page intentionally left blank
PARTXIProfessional
Project – 10
This page intentionally left blank
Project 10
Networking and
Remoting in
VC++.NET
Project 10 Overview
Networking applications on the Windows platform can be built as protocolspecific applications that use sockets for protocols, such as TCP and UDP, or applications that use platform-specific protocols or technologies, like DCOM, for communication. Building remote applications using DCOM is easier than doing it with sockets. However, developing applications using sockets is more flexible and can be adapted to other platforms also.
DCOM is widely used to create client/server and n-tier applications on the Windows platform. However, in the .NET platform, it has been replaced by the .NET Remoting technology. .NET Remoting provides a way for applications in different machines/domains to communicate with each other.
This section has two projects: one covers the basics of networking and the other caters to remoting.
The first project that illustrates networking guides you in creating a chat application using socket programming. The second project that illustrates remoting guides you in creating a Quiz application.
The concepts that you will use in these two projects include the following:
Sockets
.NET Remoting
