|
i wrote a simple line of code that retrives a value from a static XML file but my problem that it returns diffrent result every time it runs, the line is:
string asd = VoteData.DocumentElement.ChildNodes[1].ChildNodes[1].InnerText;
maybe that happen coz the file is not completely loaded , i'm using C# but i don't found any method that let me know if the file is completely loaded or not, i know that theres a function in javascript which is : readyState that do the job, but i can't found any in C#, can anyone help ?
thanx in advance.
|
|
|
|
|
Hi Guys,
I am using XML 2.0 to parse some files in Windows CE .NET 4.2. I am thinking of using XML 3.0 for parsing purpose. Will this increase the performance? Will this improve the speed of parsing?
If you guys have any articles on this please send me.
With regards
A.Santosh
|
|
|
|
|
Hi..
I am having some problems with the xmldocument. Below is my code...can anyone tell me why the output is not well formed..this is my ouput for the following code...
<?xml version="1.0" ?>
- <Persons>
- <Person Name="v" Age="00">
<Title="v" />
</Person>
</Persons>
why is the Title element not complete???
XmlDocument xmlDoc = new XmlDocument();
XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0",null,null);
XmlElement rootNode = xmlDoc.CreateElement("Persons");
xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
xmlDoc.AppendChild(rootNode);
XmlElement Node = xmlDoc.CreateElement("Person");
Node.SetAttribute("Name", name);
Node.SetAttribute("Age", age);
xmlDoc.DocumentElement.AppendChild(Node);
XmlElement Node1 = xmlDoc.CreateElement("Title");
Node1.SetAttribute("Title", title);
Node.AppendChild(Node1);
Thank you
|
|
|
|
|
The output IS well formed. When a node does not have children, it can be shown like this:
<Title></Title>
OR like this:
<Title/>
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Ooops - I meant to say that <Title/> is the same as <Title></Title>, but I forgot to check the little box
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Hi
I have a few textbox entries that i have written to an xml file and now I have to add a datasource as its child node. Any ideas on how to achieve this. I did try WriteXml method for datasource but this does not write to the file as a child node.
This is what I am trying to do
<Query name = "XYZ", age = "123" >
<Criteria>
<criterion display = "aaaa", commname = "kkkkkk">
</criterion>
<Criteria>
<Query>
The query's name and age are textbox entries and the Criteria is a part of the dataset. So i am trying to insert <Criteria> as child node to <query>
Any ideas will be greatly appreicated
Thanks in advance
|
|
|
|
|
hi, I think you can write your Criteria node to, say XmlDocumentFragment (using XmlWriter ), and then append it as node to your original XML - assumming it's in XmlDocument or similar (basicaly everything with AppendChild method ). Or you can probably work with XmlWriter directly.
Does it help?
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
David
I looked into XmlWriter class. The problem is writing the complete dataset individually by adding elements and its attributes. Criteria has a about 10 columns that I did not specify in the mail. If I were to use XmlWriter then I would have to append every single column as an element. But the datasource's writeXml method takes care of everything. Would you happen to know how I can create a document fragment and somehow use ds.WriteXml("Filename") method
Thanks!!!
Rekha
|
|
|
|
|
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.
|
|
|
|