Posts tagged ‘download’

XML Class Generator for C# using XSD for deserialization

Let’s say we have an XML file and we want to deserialize that file to our implemented class. This is an easy task if the XML file is simple. However if it has more complex types, it can take a long time to implement the class without error. XSD comes with .Net framework SDK. I does not have a user interface, we can access it from the command line tools.

  1. We start it from Visual Studio 2005 -> Visual Studio Tools -> Visual Studio Command Prompt .
  2. Next we need to have a valid XML file that I want to generate the class from. I just use for this sample, the xml output of the yahoo search REST query. Just dowload the xml output of the query
    Yahoo Search xml+class+generator or any other xml file that you want to generate the class from. We save the file as xml.
  3. We use the command xsd to the xml file to generate the xsd schema file.
  4. D:\\test>xsd webSearch.xml
    Microsoft (R) Xml Schemas/DataTypes support utility
    [Microsoft (R) .NET Framework, Version 2.0.50727.42]
    Copyright (C) Microsoft Corporation. All rights reserved.
    Writing file ‘D:\\test\\webSearch.xsd’.
    D:\\test>

  5. Next we use the generated xsd file to generate our class. The generated xsd can contain multiple class, so it would be better to use /classes switch. The default language is C#; however you might want to use it in your Visual Basic Project, to do that just add the switch /language:vb
  6. D:\\test>xsd webSearch.xsd /CLASSES /language:vb
    Microsoft (R) Xml Schemas/DataTypes support utility
    [Microsoft (R) .NET Framework, Version 2.0.50727.42]
    Copyright (C) Microsoft Corporation. All rights reserved.
    Writing file ‘D:\\test\\webSearch.vb’.
    D:\\test>xsd webSearch.xsd /CLASSES
    Microsoft (R) Xml Schemas/DataTypes support utility
    [Microsoft (R) .NET Framework, Version 2.0.50727.42]
    Copyright (C) Microsoft Corporation. All rights reserved.
    Writing file ‘D:\\test\\webSearch.cs’.

  7. Now we have the class file that we use to deserialize the xml object without any exception. So I add the XML file and the generated cs file to my project.
  8. using System;
    using System.Collections.Generic;
    using System.Text;
     
    namespace XSDTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                System.IO.StreamReader str = new System.IO.StreamReader("webSearch.xml");
                System.Xml.Serialization.XmlSerializer xSerializer = new System.Xml.Serialization.XmlSerializer(typeof(ResultSet));
                ResultSet res = (ResultSet) xSerializer.Deserialize(str);
                foreach (ResultSetResult r in res.Result)
                {
                    Console.WriteLine(r.Title);
                    Console.WriteLine(r.Summary);
                    Console.WriteLine();
                }
                str.Close();
     
                Console.ReadLine();
            }
        }
    }

  9. Here is the output :
  10. XML Class Generator for C++
    Oracle9i XML Developer’s Kits Guide – XDK. Release 2 (9.2) Part Number A96621-01
    . 19. XML Class Generator for C++ This chapter contains the following sections:
    Accessing XML C++ Class Generator … Accessing XML C++ Class Generator. The XML
    C++ Class Generator is provided with Oracle9i and is also available for XML Class Generator for Java
    Oracle9i XML Developer’s Kits Guide – XDK. Release 2 (9.2) Part Number A96621-01
    . 7. XML Class Generator for Java. This chapter contains the following sections:
    Accessing XML Class Generator for Java … The Oracle XML Class Generator for Java is provided with Oracle9i’s XDK for Java …

As you may see this is the easiest and exceptionless solution for using xml output of some web services. What we simply do is generate the classfile, deserialize the xml file to our class and use it.

Download

.

WordPress Binary Blue Localization Problem Solved

I have the same localization problem with other guys that run binary blue theme. For details, you can read the post about Binary Blue Localization
I try and test from my home computer and the localization works perfect. However my server somehow doesn’t let me to do it. I tried every combination of the naming for the WPLANG and for the PO filename. My site was still displaying in german. So I decided to write a simple utility to convert the main files to the localized files. After 2 hours of hard coding I successed with localization using the PO text file.
Here is the tool to localize binary blue to your language using the PO file.

.

To use the program you need to have .Net Framework 2.0 installed. Also you need to download the desired PO file and the theme itself. After that you can run the program to rewrite the files for you.
I don’t know if anybody is interested with the source code, if you do please let me know.

How to use it

  • Run the program
  • Initial Screen of PO Integrator

  • Select folders desired, destination folder should be empty!
  • PO Integrator selected files and folders

  • Click Start, and you are done. Copy the files to the default themes location in the web server
  • PO Integrator Operation Complete