|
Using "Reflection" might be an option.
|
|
|
|
|
Hi to everybody,
I need some help to convert a XML DataSet to an Excel file. I actually using this code:
Private Sub TransformXML(ByVal xmlDoc As XmlDataDocument, _
ByVal strXSLPath As String, _
ByVal strSavePath As String)
Dim xt As New XslCompiledTransform
Dim tw As XmlTextWriter
tw = New XmlTextWriter(strSavePath, System.Text.Encoding.UTF8)
tw.Formatting = Formatting.Indented
tw.Indentation = 3
tw.WriteStartDocument()
xt.Load(My.Application.Info.DirectoryPath & strXSLPath)
xt.Transform(xmlDoc, Nothing, tw)
tw.Close()
End Sub
The XSLT follow here :
<xsl:stylesheet version="1.0"
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:my-scripts"
xmlns ="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" >
<xsl:template match="/">
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns ="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<xsl:apply-templates/>
</Workbook>
</xsl:template>
<xsl:template match="/*">
<Worksheet>
<xsl:attribute name="ss:Name">
<xsl:value-of select="local-name(/*/*)"/>
</xsl:attribute>
<Table x:FullColumns="1" x:FullRows="1">
<Row>
<xsl:for-each select="*[position() = 1]/*">
<Cell>
<Data ss:Type="String">
<xsl:value-of select="local-name()"/>
</Data>
</Cell>
</xsl:for-each>
</Row>
<xsl:apply-templates/>
</Table>
</Worksheet>
</xsl:template>
<xsl:template match="/*/*">
<Row>
<xsl:apply-templates/>
</Row>
</xsl:template>
<xsl:template match="/*/*/*">
<Cell>
<Data ss:Type="String">
<xsl:value-of select="."/>
</Data>
</Cell>
</xsl:template>
</xsl:stylesheet>
The problem is that the XSLT must be generic because the DataSet it's always different. I would like to retrieve the datatype from the DataSet schema and create the Excel file properly. The XSLT attached perform only a simple transformation.
Can anyone help me with XSLT and kindly provide a better implementation?
Thanks in advance to anyone will replay
|
|
|
|
|
Dim ds4xmlcsv As New DataSet
Dim export As New ConvertXMLtoCSV
Dim f1 As File
Dim fullpath As String
Try
ds4xmlcsv.ReadXml(cc)
export.Export(ds4xmlcsv, True)
ds4xmlcsv.Clear()
If MsgBox("The Transfer is Complete", MsgBoxStyle.MsgBoxSetForeground.OKOnly, "Thank You") = MsgBoxResult.OK Then
btntrs2csv.Enabled = False
Exit Sub
End If
Catch errormsg As Exception
MsgBox(errormsg.Message + sessiontime.Now)
End Try
Public Function Export(ByVal ds As DataSet, ByVal exportcolumnheadings As Boolean) As String
'Dim ts11 As String
'ts11 = txtinputxmltext
'TextBox1.Text = ""
Dim ts As String
'Dim rep As String
Dim ts22 As String
ts22 = "XML2CSV.csv"
ts = Path.GetFileName(txtsavetext)
fname = txtsavetext.Replace(ts, ts22)
Dim header As String
Dim body As String
Dim record As String
Dim f As file
Dim ii As Integer
'Dim cc As String
'cc = "C:\bin\XMLInput.csv"
'f.CreateText(cc)
If f.Exists(fname) Then
f.Delete(fname)
End If
Dim writer As StreamWriter = New StreamWriter(fname)
If exportcolumnheadings Then
For Each col As DataColumn In ds.Tables(0).Columns
header = header & Chr(34) & col.ColumnName & Chr(34) & ","
Next
header = header.Substring(0, header.Length - 1)
writer.WriteLine(header)
writer.Close()
End If
For Each row As DataRow In ds.Tables(0).Rows
Dim arr() As Object = row.ItemArray()
For i As Integer = 0 To arr.Length - 1
If arr(i).ToString().IndexOf(",") > 0 Then
record = record & Chr(34) & arr(i).ToString() & Chr(34) & ","
Else
record = record & arr(i).ToString() & ","
'cc.Concat(header, record)
End If
Next
'If ii = 0 Then
' Dim writer2 As StreamWriter = New StreamWriter(cc, False)
' writer2.WriteLine(record)
' writer2.Close()
' ii = 1
'Else
Dim writer2 As StreamWriter = New StreamWriter(fname, True)
writer2.WriteLine(record)
writer2.Close()
'End If
body = body & record.Substring(0, record.Length - 1) & vbCrLf
record = ""
Next
If exportcolumnheadings Then
Return header & vbCrLf & body
'writer.WriteLine(header & vbCrLf & body)
'writer.Close()
Else
Return body
'writer.WriteLine(body)
End If
End Function
bharath.s
-- modified at 5:52 Friday 17th March, 2006
|
|
|
|
|
Thanks for your reply, but I want to convert my XML to XLS using XSLT.
Here an example of what I want to have!
http://support.microsoft.com/?kbid=319180
The code posted already work, I need only a better implementation of the stylesheet...
Thanks again
|
|
|
|
|
Im new to using Xml with C#. I have been hacking around at one section for a day now and can't get it to work at all. Rather than confuse you with my shambles code, I will jsut explain the concept. Im also slightly confussed, or misslead with my understanding of the type deffinitions, and their methods for subtrees.
<code>
XML...
<Root>
<MajorKey att="MAJattribute1">
<MinorKey att="MINattribute1">
<Value>value1</Value>
</MinorKey>
<MinorKey att="MINattribute2">
<Value>value2</value>
</MinorKey>
</MajorKey>
<MajorKey att="MAJattribute2">
<MinorKey att="MINattribute3">
<Value>value3</Value>
</MinorKey>
<MinorKey att="MINattribute4">
<Value>value4</value>
</MinorKey>
</MajorKey>
</Root>
</code>
Im having trouble getting it to create a nodelist to children underneath a node based on it's att (attribute) value. Also, I want to extract that attribute value into a string so "MAJattribute1" would gointo a string inside the loop for that node treversal.
Any help, or suggestions.
I have spent hours and hours reading, and cant seem to find anything to pinpoint this...only ever creating attributes indide a single node, not looping through based on the attribute value.
IM GETTING STRESSED
Regards
njc
|
|
|
|
|
I Want Voip Concept and avilable web sites
|
|
|
|
|
Hi evry body
---------------
I want an Article about XMl
that this Article explain what is the XML and what we can do with XML
I want a little history of XML and some informations about XML WebService
---------------
---------------------
Areff Bahrami(KAVEH)
Areff.HB@Gmail.com
---------------------
|
|
|
|
|
http://www.topxml.com/php_xml_dom/default.asp
|
|
|
|
|
thanks WhiteSky
---------------------
Areff Bahrami(KAVEH)
Areff.HB@Gmail.com
---------------------
|
|
|
|
|
http://www.w3schools.com
for beginner in XML
"I find that the harder I work, the more luck I seem to have."
|
|
|
|
|
How to add Images into my <question> or <answer>? My code is as below.
-----------------------------------------------------------------------------
<quiz xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="quiz.xsd">
<mchoice>
<question>When you create a new document, it always displays behind the Toolbox. Which of the following actions will ensure it always opens flush with the Toolbox?</question>
<answer>Using the keyboard shortcut key Ctrl+N [Cmd+N] to always create a new document</answer>
<answer>Making sure the Options bar is not parked flush with the top of the screen; allowing a gap of a few pixels in between</answer>
<answer>Holding down the Alt [Opt] key as you click the OK button in the New dialog</answer>
<answer correct="yes">Moving the Toolbox a few pixels away from the edge of the screen</answer>
</mchoice>
|
|
|
|
|
Yeah u found the solution use this line of code
<![ CDATA [[img]../pic.jpg[/img]]]>
|
|
|
|
|
Hi,
VS 2005 / C#
Simple situation: A DataTable with some columns and rows added. But when using the WriteXML method to create an XML file from this table it gives me the following output:
<?xml version="1.0" encoding="utf-8"?>
<DocumentElement>
<Batch_Table>
<Height>18</Height>
<Width>75</Width>
<Program>1</Program>
<Length1Min>18</Length1Min>
<Length1Max>60</Length1Max>
<Price1>1000</Price1>
</Batch_Table>
<Batch_Table>
<Height>25</Height>
<Width>125</Width>
<Program>2</Program>
<Length1Min>12</Length1Min>
<Length1Max>40</Length1Max>
<Price1>1200</Price1>
<Length2Min>40</Length2Min>
<Length2Max>60</Length2Max>
<Price2>1300</Price2>
</Batch_Table>
...and so on. The problem is that each row/record of the table is named as the TABLE (which is called "Batch_Table"). This is wrong! How can I fix this?
Thanks.
/Magnus
|
|
|
|
|
how to get microsoft.xmldom?
I dont find this activex
can you help me
thanks
|
|
|
|
|
WhiteSky wrote: how to get microsoft.xmldom?
this is the syntax.....
obj = new ActiveXObject('Microsoft.XMLDOM');
or
obj = new ActiveXObject('MSXML2.DOMDocument.4.0');
use either of the two in ur scripts
sathy
|
|
|
|
|
I need to 'Microsoft.XMLDOM'
|
|
|
|
|
Hi,
I am having an XML file which has two elments id & StartDate, Iam using Visual C# > XMLTextReader Object "reader" to read this file, if the nodetype is text and the elementname is startdate then write the startdate by converting it. If you see the below code hope every thing gets clear
Insted of getting the value I want to search if the XmlNodeType is text then I want to get the datatype (i.e. date or string or int32 etc.) of the element insted of the value
System.IO.Stream objStream = new System.IO.MemoryStream();
DataSet objDs = new DataSet();
objDs = getData();
XmlTextReader reader = new XmlTextReader(objDs.GetXml(), XmlNodeType.Element, null) ;
Response.ContentType = "text/xml";
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8);
writer.Indentation = 4;
writer.WriteStartDocument();
string elementName = "";
while(reader.Read())
{
switch(reader.NodeType)
{
case XmlNodeType.Element:
writer.WriteStartElement(reader.Name);
elementName = reader.Name;
break;
// In the below case I have a problem I want to get the datatype of the node insted of the data
case XmlNodeType.Text:
if(elementName == "StartDate")
writer.WriteString(XmlConvert.ToDateTime(reader.Value).ToString());
else
writer.WriteString(reader.Value);
break;
case XmlNodeType.EndElement:
writer.WriteEndElement();
break;
}
|
|
|
|
|
The type of the element is defined in the schemas, there is no way to get this information from the xml document alone.
Denevers
|
|
|
|
|
hi all,i'm creating a mobile appliction with ms vs2005 release edition, im using a webservice from www.webservicex.com and i get the exception with the details :
Status :System.Net.WebExceptionStatus.ConnectFailure
System.Net.WebException was unhandled
Message="Could not establish connection to network."
StackTrace:
at System.Net.HttpWebRequest.finishGetResponse()
at System.Net.HttpWebRequest.GetResponse()
at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse()
at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse()
at System.Web.Services.Protocols.SoapHttpClientProtocol.doInvoke()
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke()
at DeviceApplication2.net.webservicex.www.lengthUnit.ChangeLengthUnit()
at DeviceApplication2.Form1.button1_Click()
at System.Windows.Forms.Control.onclick()
at System.Windows.Forms.Button.onclick()
at System.Windows.Forms.ButtonBase.WnProc()
at System.Windows.Forms.Control._InternalWnProc()
at Microsoft.AGL.Forms.EVL.EnterMainLoop()
at System.Windows.Forms.Application.Run()
at DeviceApplication2.Program.Main()
&here's my code:
private void button1_Click(object sender, EventArgs e)
{
net.webservicex.www.lengthUnit l = new
DeviceApplication2.net.webservicex.www.lengthUnit();
double x = l.ChangeLengthUnit(120, DeviceApplication2.net.webservicex.www.Lengths.Feet, DeviceApplication2.net.webservicex.www.Lengths.Meters);
MessageBox.Show(x.ToString());
}
please tell me where is the error (i'm deploying it using the device emulator and the active sync program)
|
|
|
|
|
Hi,
I wonder if anyone can offer some advice on the best way to accomplish this:
I have an existing asp.net app that displays products from a catalogue, data stored in access. My friend has provided an xml feed from their database so that I can incorporate their data into my app, without the need to duplicate the data. How would I go about building a feed mechanism where by I can display their data whenever a user loads my app?
I would guess this is a common requirement.
Many Thanks
Kieran
|
|
|
|
|
am i getting u right ...
u friend as provided an access for u to get the datas as xml ....
and u r askin how get tht data and display it in ur app???
if tht is the case u write a webservice for tht ... to get the datas from there....
if not provide some more details
sathy
|
|
|
|
|
Hi everybody,
I'm looking for an activex control (or anything that could be interfaced easily with MFC) which provides XML code editing with the following features:
- syntax highlight
- auto completion
- auto validation of the syntax
Something real simple like the VS.Net XML Editor.
I've searched for one during many hours, but unsuccessfully...
Thanks
|
|
|
|
|
could anyone please suggest how to convert a .mat file to xml
|
|
|
|
|
I have the following code sequence:
MemoryStream memStream= new MemoryStream();
XmlTextWriter xmlWriter= new XmlTextWriter(memStream, System.Text.Encoding.UTF8);
doc.Save(xmlWriter, myCommand );
string xmlCmd= System.Text.Encoding.ASCII.GetString(memStream.ToArray());
System.Console.WriteLine( "xmlCmd= {0}", xmlCmd );
Here's the command it creates:
o;?<mycommand xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
...="" lots="" of="" valid="" xml="" here
<="" mycommand="">
Why the 'o;?' characters in front of the command?
|
|
|
|
|
Hi,
could anybody help with this?
I want to replicate this hard coded xml by drawing the data from a sql database.
I have had some sucess but I would like to omit "PR_Ref" entry from the resulting dataset,
but I do need it for the foreignkey/primarykey. I'm not sure if the string conversion is
correct either.
I need to read the resulting dataset to a string. This is the original hard coded bit:
______________________________________________________________________________________________
string xmlData;
xmlData = "<newdataset>";
xmlData += " <group>";
xmlData += " <name>Project 1";
xmlData += " <blockcolor>#ff0000";
xmlData += " <block>";
xmlData += " <href>activity.aspx?ActID=7";
xmlData += " <startdate>2005-04-01T00:00:00.0000000+01:00";
xmlData += " <enddate>2005-04-03T00:00:00.0000000+01:00";
xmlData += " <name>First part";
xmlData += " ";
xmlData += " <block>";
xmlData += " <href>activity.aspx?ActID=13";
xmlData += " <startdate>2005-04-06T00:00:00.0000000+01:00";
xmlData += " <enddate>2005-04-06T00:00:00.0000000+01:00";
xmlData += " <name>blah, blah";
xmlData += " ";
xmlData += " ";
xmlData += " <group>";
xmlData += " <name>Project 2";
xmlData += " <blockcolor>#ff0000";
xmlData += " <block>";
xmlData += " <href>activity.aspx?ActID=14";
xmlData += " <startdate>2005-04-06T00:00:00.0000000+01:00";
xmlData += " <enddate>2005-04-09T00:00:00.0000000+01:00";
xmlData += " <name>blah, blah";
xmlData += " ";
xmlData += " <block>";
xmlData += " <href>activity.aspx?ActID=15";
xmlData += " <startdate>2005-04-06T00:00:00.0000000+01:00";
xmlData += " <enddate>2005-04-09T00:00:00.0000000+01:00";
xmlData += " <name>blah";
xmlData += " ";
xmlData += " ";
xmlData += "";
______________________________________________________________________________________________
This is my attempt
____________________________________________________________________________________________
DataSet myds = new DataSet();
OleDbDataAdapter myGroupAdapter;
OleDbDataAdapter myBlockAdapter;
DataColumn primaryKey = new DataColumn();
DataColumn ForeignKey = new DataColumn();
OleDbConnection myConn = new OleDbConnection("Provider=SQLOLEDB.1; Persist Security Info=False; Data Source=xxx; Initial Catalog=xxx;User ID=xx;Password=xxxxxx;");
myGroupAdapter = new OleDbDataAdapter("select PR_NAME, blockcolor, PR_Ref from PM_PROJECT", myConn);
myBlockAdapter = new OleDbDataAdapter("Select href, Sub_Start, Sub_End, Sub_Name, PR_Ref from SUBTASK", myConn);
myGroupAdapter.Fill(myds, "group");
myBlockAdapter.Fill(myds, "block");
primaryKey = myds.Tables["group"].Columns["PR_Ref"];
ForeignKey = myds.Tables["block"].Columns["PR_Ref"];
DataRelation relation = new DataRelation("group", primaryKey, ForeignKey);
relation.Nested = true;
myds.Relations.Add(relation);
string xmlData = Convert.ToString((DataSet)myds);//not sure if this bit works
//I tested it with this:
myds.WriteXml("TestXML.txt")
___________________________________________________________________________________________
This was the resulting output
<newdataset>
<group>
<pr_name>Test Project
<blockcolor>#ff0000
<pr_ref>1
<block>
<href>activity.aspx?ActID=7
<sub_start>2006-02-02T00:00:00+00:00
<sub_end>2006-02-03T00:00:00+00:00
<sub_name>Start Test
<pr_ref>1
<block>
<href>activity.aspx?ActID=7
<sub_start>2006-02-03T00:00:00+00:00
<sub_end>2006-02-05T00:00:00+00:00
<sub_name>second sub for
<pr_ref>1
<block>
<href>activity.aspx?ActID=7
<sub_start>2006-02-03T00:00:00+00:00
<sub_end>2006-02-07T00:00:00+00:00
<sub_name>3rd test
<pr_ref>1
<group>
<pr_name>second Test
<blockcolor>#ff0000
<pr_ref>2
<block>
<href>activity.aspx?ActID=7
<sub_start>2006-02-01T00:00:00+00:00
<sub_end>2006-02-08T00:00:00+00:00
<sub_name>first/second
<pr_ref>2
Sorry the post is so long. Does anybody have any ideas??
Thanks
Ironstrike
|
|
|
|