|
hi,
Of course you can let dataset do lot of work for for you! you can use
<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatasetclasswritexmltopic4.asp">WriteXml(XmlWriter) </a>[<a target=_blank title='New Window' href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatasetclasswritexmltopic4.asp">^</a>]<br /> overloaded method to write columns and all into XmlWriter at once. Bt yes, you would have to write your Query element by yourself...
example:
XmlTextWriter w = new XmlTextWriter(filename);
w.WriteElementStart("query");
ds.WriteXml(w);
w.WriteElementEnd();
w.Close();
It's not exact code - just idea how to do that... I don't know exact method names and arguments from heart... I think this way it should work...
As for XmlDocument, sorry. I forgot you can load XML into it with XmlReader, bt AFAIK you can't write into it with XmlWriter. My fault.
hmm or you can save dataset into file, than load it to XmlDocument and than you can create XmlDocumentFragment from it. Next step is to append Criteria node to Query element - It suppose to have Query also loaded in (another) XmlDocument - probably less efficient solution than the first one ( with XmlTextWriter).
David
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
|
Hi.
Ive been looking on the net for weeks in trying to convert a .NET dataset to the standard ADO recordset schema - but with no luck. Ive had a go myself, but can't seem to produce the results I want.
Heres the dataset:
<?xml version="1.0" encoding="utf-8"?>
<DataSet xmlns="http://tempuri.org/mytestWS">
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="en-GB">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="ProductID" type="xs:int" minOccurs="0" />
<xs:element name="ProductName" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<Table diffgr:id="Table1" msdata:rowOrder="0">
<ProductID>189</ProductID>
<ProductName>Product Name 1</ProductName>
</Table>
<Table diffgr:id="Table2" msdata:rowOrder="1">
<ProductID>313</ProductID>
<ProductName>Product Name 2</ProductName>
</Table>
</NewDataSet>
</diffgr:diffgram>
</DataSet>
And here is what im trying to achieve:
<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:rs=""urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
<s:Schema id="RowsetSchema">
<s:ElementType name="row" content="eltOnly">
<s:AttributeType name="ProductID"/>
<s:AttributeType name="ProductName"/>
<s:Extends type="rs:rowbase"/>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row ProductID="189" ProductName="Product Name 1"/>
<z:row ProductID="313" ProductName="Product Name 2"/>
</rs:data>
</xml>
As you can see in the Dataset I need to extract name="ProductID" from the <xs:element>, and write it to the <s:AttributeType> node - same with the <z:row>
Could anyone help me here?
J
|
|
|
|
|
Hello
I am facing a strange encoding problem using xsl transformation.
Concisely, i execute a SQL statement to fill a recordset which contain
some fields with Greek Characters saved as UTF-16 (on SQL Server 2000 using nvarchar) ,which then i save to the Response object of an ASP page as xml (adPersistXML).Then i use an xsl file
to transform XML to HTMl.The problem is that when i see the page in the
internet explorer instead of the greek character i get something like this
"ΕΛΛΗΞΞ™ΞšΞŸΞ£ Ξ¤Ξ™Ξ¤Ξ›ΞŸΞ£" . Moreover when i do a "view source" and
see the HTML source using Notepad the Text is displayed correctly in Greek.
I am using the following ASP code to do the transformation :
<br />
' rs is an ADO recordset filled with data from a sql Select statement<br />
styleFile = Server.MapPath(xslfile)<br />
set stylexml =Server.CreateObject("MSXML2.FreeThreadedDOMDocument")<br />
stylexml.async = false<br />
stylexml.load(styleFile)<br />
<br />
<br />
<br />
set sourcexml = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")<br />
sourcexml.async = false<br />
<br />
rs.Save sourcexml,1 ' Save as adPersistXML<br />
set rs=Nothing<br />
<br />
<br />
<br />
strPath=BuildPath(id,18)<br />
dim xslty,xslProc<br />
set xslt = Server.CreateObject("MSXML2.XSLTemplate")<br />
xslt.stylesheet =stylexml<br />
Set xslProc =xslt.createProcessor()<br />
xslProc.input=sourcexml<br />
xslProc.addParameter "Path",escape(strPath)<br />
Response.charSet = "UTF-8"<br />
xslProc.output = Response<br />
xslProc.transform
The xsl file is created using visual studio , saved as unicode file and inside it i define the encoding like this : <xsl:output encoding="utf-16" method="html" version="4.0">
I know that the problem was to do with "BIG endian" and "Little endian" switces
the ADO recordset is being saved as UTF-16 big endian (UTF-16BE). Rather, the data is. "Endianness" only matters when serializing UTF-16. When it's in-memory, it doesn't
matter. When there is no byte order mark, it's supposed to be Big Endian.
Although i've not managed to find any solution.
Any ideas ?
Thanks in advanced
Theodore Papadopoulos
|
|
|
|
|
oups , i forgot to include the xsl:output i use.
The xsl file is created using visual studio , saved as unicode file and inside it i define the encoding like this :
<xsl:output encoding="utf-16" method="html" version="4.0">
|
|
|
|
|
encoding="utf-16" method="html" version="4.0"
|
|
|
|
|
hi,
I have some ideas <smal;>(probably not the solution, bt one never knows ). First make sure that problem is not caused by IE settings Do you have encoding in IE set to UTF-16 (or auto-select)? (View->Encoding ...)
Second, teo_xp wrote:
Response.charSet = "UTF-8"
Shouldn't there be UTF-16 instead?
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
dnh wrote:
Do you have encoding in IE set to UTF-16 (or auto-select)? (View->Encoding ...)
Second, teo_xp wrote:
Response.charSet = "UTF-8"
dnh wrote:
Shouldn't there be UTF-16 instead?
About the first : i have auto-select.
About the second : You are right it has to be UTF-16 and in fact UTF-16 is what i currently use. The UTF-8 was wrong inserted from a previous test file i had.
|
|
|
|
|
hi again,
teo_xp wrote:
About the first : i have auto-select.
Out of curiosity, you tried to set it explicitly to UTF-16, did you? (I'll never ever belive IE)
I've googled a little and found this[^] so far (and your question in another forum).
Basicaly, there are tree points where encoding can go bad:
SQL DB-> recordset
recordset->XSLT transformed file
XSLT transformed file->browser
<code>
' rs is an ADO recordset filled with data from a sql Select statement <- UTF-16 (nvarchar from SQL)
styleFile = Server.MapPath(xslfile)
set stylexml =Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
stylexml.async = false
stylexml.load(styleFile)
set sourcexml = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
sourcexml.async = false
rs.Save sourcexml,1 ' Save as adPersistXML <-UTF-8, see link below
set rs=Nothing
strPath=BuildPath(id,18)
dim xslty,xslProc
set xslt = Server.CreateObject("MSXML2.XSLTemplate")
xslt.stylesheet =stylexml
Set xslProc =xslt.createProcessor()
xslProc.input=sourcexml
xslProc.addParameter "Path",escape(strPath)
Response.charSet = "UTF-16"
xslProc.output = Response
xslProc.transform <- according to first link I gave u, u may try transformNodeToObject()
</code>
"A Recordset saved in XML format is saved using UTF-8 format. When such a file is loaded into an ADO Stream, the Stream object will not attempt to open a Recordset from the stream unless the Charset property of the stream is set to the appropriate value for UTF-8 format." (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthrstsave.asp[^])
Didn't that guy in other forum said it preserves your UTF-16?
I hope we moved on a little
[edit]
Do you have xml declaration WITH encoding, or at least meta tag with encoding in your resultant HTML file ?
[/edit]
David
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Hi , and thanks for your help
I am quite sure that the problem source is the ADO save method that outputs UTF-8.
The problem is that when i changes everything to UTF-8 (The asp that insert the data , the Response.charset , and the xsl file encoding ) i still have the problem and even more , doing view source the page i can't see the correct encoding as i can when i use UTF-16.
<small><b>dnh wrote:</b></small>
<i>Do you have xml declaration WITH encoding, or at least meta tag with encoding in your resultant HTML file ?</i>
I get this , that i think it's ok:
<META http-equiv="Content-Type" content="text/html; charset=utf-16">
Another dillema that i face is the format that i should save the xsl file using visual studio 6.
I have the following options : 1) Text file , 2) UTF-8 , 3) Unicode 4) Big-endian Unicode
Currently i am using the Unicode , but i've also try the Big-endian without any improvment.
finally , i have to say that i have try also the transformNodeToObject() method without success.
Anyway ,
Thanks again
|
|
|
|
|
Hi,
i am in a situation to get the XML out from an object in dotnet.
if i assign the values for the fields i am getting the nodes corresponding to the fields in the XML.
But i need to get the XML structure without asigning the values for the fields.(The XML struvture of the object).
How can i achieve this ?
Thanks in advance.
Sakthi
|
|
|
|
|
I create xml file to DataSet.WriteXml method. but xml file is null when table has not data in the database. Then create dataset from the xml file to DataSet.ReadXml method. I find out that dataset's tables is zerotable.how to do it that no data, table's struct still have?
|
|
|
|
|
If the SQLXMLCommand.text property is set to a stored procedure(or template) and the ExecuteStream method is called an exception is thrown whether or not it is processed on the server or the client. The exception is posted here:
<br />
Exception Details: System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x80040E21.<br />
<br />
Source Error: <br />
<br />
Line 36: 'sxcmd.RootTag = "FullName"<br />
Line 37: Dim MemSt As MemoryStream<br />
Line 38: MemSt = sxcmd.ExecuteStream()--->error occuring here<br />
Line 39: Response.Write(MemSt.Length)<br />
Line 40: Dim strRdr As New StreamReader(MemSt<br />
After much searching, try to find what HRESULT:0X800040E21 is, and you will be surprised as to what I found. It says that an error occured . How much more user friendly message do you want?
|
|
|
|
|
maybe a stupid question, bt is that stored procedure ok?
I mean does it really return XML? (contains FOR XML modifier)
If not, take a look at this[^]
mysorian wrote:
How much more user friendly message do you want?
ah. It's COM. You can expect everything from COM but not being user friendly
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Hi David:
Nothing is stupid, everything needs an explanation. Thanks for the link to the article, but it is not using the ExecuteStream method.
sincerely,
mysorian
ah! too many things under the hood
|
|
|
|
|
mysorian wrote:
Nothing is stupid
So, how'd you call somebody who produced 53MB (!) ASPX web form due to buggy XSLT? (jup, I have my day!)
So, does it mean that SP doesn't return XML? I basically told you to look at that link only IF it isn't ok
mysorian wrote:
but it is not using the ExecuteStream method.
No it's not, bt it shows you how to make SP produce XML results. Btw I think you use ExecuteStream right way.
You can use ad-hoc SQL statements or you can also execute stored procedures that return XML. Consider the following stored procedure:
CREATE PROCEDURE dbo.GetEmployeesXml
AS
SELECT * FROM employees FOR XML AUTO
RETURN
This can be executed as follows:
SqlXmlCommand cmd = new SqlXmlCommand(NorthwindConnString);
cmd.RootTag = "Employees";
cmd.CommandText = "EXEC GetEmployeesXML";
XmlReader xr = cmd.ExecuteXmlReader();
I suspect ExecuteStream() fails because SP return non-XML data (some table or something like that).
If you can, try ExecuteReader() (and XmlReader instead of stream). That way you can be sure if problem is in SP or somewhere else. (If it fails than problem is probably in SP)
mysorian wrote:
ah! too many things under the hood
Is that your sig or do you say this to me?
David
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
David:
There is more to it than meets the eye...
-------------
PROCEDURE dbo.GetEmployeesXml<br />
AS<br />
SELECT * FROM employees FOR XML AUTO<br />
RETURN
------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
'Put user code to initialize the page here<br />
If Not IsPostBack Then<br />
Dim sxcmd = New SqlXmlCommand("PROVIDER=SQLOLEDB.1;SERVER=XPHTEK;DATABASE=Northwind;INTEGRATED SECURITY=sspi;")<br />
sxcmd.RootTag = "Employees"<br />
sxcmd.CommandText = "EXEC GetEmployeesXml"<br />
Dim xrdr As System.Xml.XmlReader<br />
<br />
xrdr = sxcmd.ExecuteXmlReader()<br />
Response.Write(xrdr.HasValue)<br />
<br />
End If<br />
End Sub
----------------------------
Exception Details: System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x80040E21.<br />
<br />
Source Error: <br />
Line 32: Dim xrdr As System.Xml.XmlReader<br />
Line 33: <br />
Line 34: xrdr = sxcmd.ExecuteXmlReader()--->error generted here<br />
Line 35: Response.Write(xrdr.HasValue)<br />
Line 36: While xrdr.Read
-----------------------
Now I substitute the 'stored procedure' by the statement used in the procedure, voila! No exception thrown.
|
|
|
|
|
Hi, I am trying to use MSXML to parse an XML document. I have a document that has several special characters such as é à and others ( accents used in latin derived languages like french and spanish ).
When MSXML encounter such a character it gives an error message saying : An invalid character was found in text content.
I can remove all the accents either by hand or programmaticly but the thing is I need to conserve them. I am using data from the XML and if the data is not accented it can be confusing and be seen as spelling mistakes.
Is there a way to have MSXML read a document which contains accentuated characters and for it to store that data correctly ?
EDIT : I tried putting at the start of the XML document but I still have this error.
|
|
|
|
|
Are you using appropriate encoding? Sounds like problem is here. UTF-8 is default encoding for XML. However, I am not sure what is default encoding for MSXML parser. (is it that one in IE? I don't trust anything around IE)
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Yes MSXML is the one from IE, unfortuntly I must use it.
I tried not specifying an encoding in my file and specifying UTF-8 in my file but to no effect. I don't know if I can specify it from the parser.
|
|
|
|
|
Ok I have found it I must specify ISO-8859-1 encoding at the start of the file like this : <?xml version="1.0" encoding="ISO-8859-1"?>
EDIT : Change the comment formating because the XML tag would not show up.
|
|
|
|
|
Anonymous wrote:
unfortuntly I must use it.
That says everything!
David
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
I’ve got a problem, I’m hoping someone out there has the answer to. I am a .Net programmer working for a small educational software company. I need to add some simple reporting to the project I am working on. Basically, I need to take some data from my database and format a RTF document from it that can then be displayed in a rich text box or printed or saved or whatever. Unfortunately RTF code is not so easy to understand.
I was told by someone that I could use XSLT to do this. After some reading I found out that this is not exactly correct. You can use XSLT, however you still need to be able to write RTF code. I could use XSL-FO, but since .Net does not implement XSL-FO, I would need to use a third party tool in order to transform my XML data and XSLT stylesheet to RTF. My company doesn’t want to pay for one of these third party tools, nor do they want to deal with any complex licensing issues, that come along with them.
Does anyone have any suggestions on how I can accomplish this task? The reports are not complex, just some simple text formatting and tables.
Thanks for your help
|
|
|
|
|
Hi David. Would an HTML format be acceptable for your reports? I'm seeing more and more reporting modules producing HTML output that in the past would have been .rtf, and the code to launch an .html report in the default browser is simple.
|
|
|
|
|
HTML would be ok. If it could look the same on the screen as it would on printed paper. Also, I would have to learn HTML, which I thankfully have been able to avoid up to this point. Can HTML do tables and margins and such? Forgive my ignorance.
Also, the end users of the application's reporting feature will be school teachers, who aren’t known for being very computer savvy. If I use the default browser to open and view reports, I’ll get thousands of tech support calls because a teacher has lost the browser window behind the application window. It’s hard to explain the concept of “[Alt]+[Tab]” to school teachers. The application hides the task bar so that kids aren’t messing with it instead of using the application.
If I were to use HTML, I would have to use one of those browser window controls on a form in order to prevent the “[Alt]+[Tab]” problem.
Thanks
|
|
|
|