none
DataTable Extended Properties XML RRS feed

  • Question

  • Hi

    This is my context :

    - I do a SQL query and build up a DataTable set
    - I then create the XML using the DataTable XML write
    - I then msxsl.exe with a xsl file to create a "nice" html report

    Now i need to pass a couple of attributes to the xml to use in the report header
    e.g. Product & Title

    This is the problem. I have tried using extended properties but this info does not appear in the xml ..

    e.g.

                    StreamWriter writer = new StreamWriter(outputPath + ".xml");
    
                    writer.WriteLine("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
                    writer.WriteLine("<?xml-stylesheet type=\"text/Xsl\" href=\"RelNotesSummary.xsl\"?>");
    
                    // Add properties
                    resultsTable.ExtendedProperties.Add("ProductAlias", _productAlias);
                    resultsTable.ExtendedProperties.Add("Title", textTitle.Text);
                    resultsTable.AcceptChanges();
    
                    // Add the results
                    resultsTable.WriteXml(writer);
                    writer.Close();
    
    

    => So can some confirm if the extended properties are meant to be able to be written to the XML ?

    => Assuming after doing X, this does work...

    => What would be a XSL syntax to access these properties look like ?

    Thanks

    Friday, February 5, 2010 8:55 AM

Answers

  • The set of extended properties is lost at serialization time, unless you choose to add schema information.

    The WriteXml method adds extended properties to the schema using an ad hoc attribute prefixed with the msprop namespace prefix. ExtendedProperties holds a collection of objects and can accept values of any type, but you might run into trouble if you store values other than strings there. When the object is serialized, any extended property is serialized as a string.

    The MSDN documentation tells that you shouldn't store other than strings in ExtendedProperties. In truth, you can use any object as long as you are then capable of recreating your object from the serialized string.
    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    Friday, February 5, 2010 6:59 PM