Database Reference
In-Depth Information
Once your script component is configured, you can plug in the CreateNewOut-
putRows logic from one of the following patterns.
Processing XML with XmlSerializer
To process the XML file using the XmlSerializer class, we'll use the XML
Schema Definition tool to generate a set of .NET classes from our XML schema file.
From the command line, we'll specify that we want to generate classes ( /classes ),
the language we'd like to use (in this example, we'll use C#, but VB could be used as
well), the namespace of the resulting class, and the path to our schema file. We'll use
the schema file ( Customer.xsd ) for the customer data XML from Listing 9-3 . The
command line and xsd.exe output is shown in Listing 9-7 .
Listing 9-7 . XML Schema Definition Tool Command Line
C:\demos>xsd.exe /classes /language:CS
/namespace:DesignPatterns.Samples Customer.xsd
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.3038]
Copyright (C) Microsoft Corporation. All rights reserved.
Writing file 'Customer.cs'.
Note The XML Schema Definition tool is part of the Windows SDK. On most ma-
chines, it will be found in the C:\Program Files (x86)\Microsoft
SDKs\Windows\v7.0A\Bin directory. For more information on the XML Schema Defin-
ition tool, see its MSDN entry at http://msdn.microsoft.com/en-us/lib-
rary/x6c1kb0s.aspx .
The resulting Customer.cs file will have the classes we'll use in our script com-
ponent. When used with the XmlSerializer class, we can read the entire XML
Source file into an easy-to-manipulate set of objects.
Before we begin writing the CreateNewOutputRows logic, we'll need to in-
clude the Customer.cs file that we generated using xsd.exe . To do this, perform
the following steps from within the VSTA script editor environment:
 
 
Search WWH ::




Custom Search