Forum - XML Standard

Expand all | Collapse all

Any C# sample code to write out the patient and tumor records in SQL Server database to a version 21 XML file?

Jump to Best Answer
  • 1.  Any C# sample code to write out the patient and tumor records in SQL Server database to a version 21 XML file?

    Posted 23 days ago
    Hello;

    We use SQL Server database to store patient and tumor information for our provincial cancer data(Canadian Cancer Registry). We would like to write out the data in the database to NAACCR XML (version 21) directly using C# libraries. Has anyone here done the similar work?

    Thanks,

    Yali

    ------------------------------
    Yali Yang
    [CompanyName]
    ------------------------------


  • 2.  RE: Any C# sample code to write out the patient and tumor records in SQL Server database to a version 21 XML file?
    Best Answer

    Posted 22 days ago
    Hello Yali,

    Are you looking for a one-time process (or something done "once in a while"), or a fully automated solution?

    I think you will have more options if you are willing to have a manual step in the process.

    For example, if you are able to extract your data in CSV (using either the XML ID or the NAACCR numbers as column headers), then there are software you can use to convert CSV to XML (File*Pro is one of them, there might be others).

    If you are looking for a fully automated solution, I recommend you look into existing libraries to help you with that. I am not personally familiar with it, but I know that at some point CDC released a DLL to read/write XML. It was part of their XML Exchange Plus software (https://www.cdc.gov/cancer/npcr/tools/registryplus/xml-exchange-plus.htm). I took a quick look and I don't see a reference to a standalone DLL anymore, but it might be worth for you to contact them and ask about it. It might still be available somewhere else.

    You can also write the code yourself to convert CSV to XML, but that will certainly take more time than using an existing library!

    ------------------------------
    Fabian Depry
    Information Management Services, Inc.
    ------------------------------



  • 3.  RE: Any C# sample code to write out the patient and tumor records in SQL Server database to a version 21 XML file?

    Posted 22 days ago
    Edited by Qianru Wu 22 days ago

    I haven't done similar tasks before, but I think you may use SQL and XML classes in C# to do it:

    1.       Samples to read data from SQL: 

      https://stackoverflow.com/questions/14171794/how-to-retrieve-data-from-a-sql-server-database-in-c
      https://www.comeausoftware.com/2018/03/retrieve-data-sql-server-csharp/



    2.       Microsoft document for process XML, including some sample codes:

                  https://docs.microsoft.com/en-us/dotnet/api/system.xml.xmldocument?view=net-5.0

    Thanks,

    Amie Wu



    ------------------------------
    Qianru Wu
    [CompanyName]
    ------------------------------



  • 4.  RE: Any C# sample code to write out the patient and tumor records in SQL Server database to a version 21 XML file?

    Posted 21 days ago
    Thank you Fabian for the quick help. File*Pro works for me. Truly appreciated.

    I am planning to use NAACCR naaccr_data.xsd file here

    https://github.com/imsweb/naaccr-xml/tree/master/src/main/resources/xsd

    By using the xsd.exe tool in Visual Studio to generate .cs classes to match the xml schema file.  Then add these classes to my project and read my SQL Server data into the created classes, and serialize the object with XMLSerializer to get It into the xml format output. (See: Examples of XML Serialization | Microsoft Docs).

    ------------------------------
    Yali Yang
    [CompanyName]
    ------------------------------



  • 5.  RE: Any C# sample code to write out the patient and tumor records in SQL Server database to a version 21 XML file?

    Posted 21 days ago
    Thank you Amie!

    I have found a workaround by exporting data from SQL Server to a fixed column csv file using Microsoft SSIS package and use File*Pro to output csv file to a version 21 NAACCR XML.

    Cheers,

    Yali


    ------------------------------
    Yali Yang
    [CompanyName]
    ------------------------------



  • 6.  RE: Any C# sample code to write out the patient and tumor records in SQL Server database to a version 21 XML file?

    Posted 21 days ago
    Sounds great. Good luck!
    - Amie Wu

    ------------------------------
    Qianru Wu
    [CompanyName]
    ------------------------------