miscal

HI,

I've created a decryption code for an encrypted XML file. now, instead of using save command into file like 'encryptedDoc.Save("C:\tal\Desktop\account.xml")' - I want to load the XML document into dataset. what is the syntax for doing it the XML document is stored in the object 'EncryptedDoc'.

thanks in advance,

Dror.



Re: ASMX Web Services and XML Serialization XML into DATASET

rfreire

Hi,

You should use one of the overloaded versions of ReadXml DataSet method:

http://msdn2.microsoft.com/en-us/library/system.data.dataset.readxml(VS.80).aspx

In your specific case, I think you should use a StringReader to read the decrypted XML string and pass it to the ReadXml method.

Regards,

Rodrigo





Re: ASMX Web Services and XML Serialization XML into DATASET

miscal

hi Rodrigo,

thanks for your reply. I apollogize, but your answer is too general for me, I do not understand how to use the code you specified.

thanks,

Dror.





Re: ASMX Web Services and XML Serialization XML into DATASET

rfreire

Well, let's say you can provide me with either an XmlDocument or a string with the decrypted xml data.... I can use any of those methods to get a DataSet based on this information:

Code Snippet

public DataSet LoadDataSet(string xmlData)

{

StringReader sReader = new StringReader(xmlData);

DataSet ds = new DataSet();

ds.ReadXml(sReader);

return ds;

}

public DataSet LoadDataSet(XmlDocument xml)

{

return LoadDataSet(xml.OuterXml);

}

For that I'm asuming the decrypted XML data corresponds to a serialized DataSet, right

Regards,

Rodrigo





Re: ASMX Web Services and XML Serialization XML into DATASET

miscal

Hi Rodrigo,

You're assuming correctly. one more request, if possible- can you specify the code in VB (I am not familiar with C, only .NET).

I tried to "translate" it - unsuccessfully...

thanks,

Dror.





Re: ASMX Web Services and XML Serialization XML into DATASET

rfreire

Sure,

Code Snippet

Public Function LoadDataSet(ByVal xmlData As String) As DataSet

Dim sr As New StringReader(xmlData)

Dim ds As New DataSet

ds.ReadXml(sr)

Return ds

End Function

Public Function LoadDataSet(ByVal xml As XmlDocument) As DataSet

Return LoadDataSet(xml.OuterXml)

End Function

Regards,

Rodrigo





Re: ASMX Web Services and XML Serialization XML into DATASET

miscal

Hi Rodrigo,

That won't work: the first syntax you specified - I assume I need to call the function:

loaddataset(encrypteddoc)

the content of the dataset will returned in 'ds' dataset, right

there is an error: the object 'encrypteddoc' is a XML document, and the cdoe tries to call it in 'xmlData' as a string, so it returns an error.

maybe I'm wrong with the way I call the function the dataset I need to be loaded called 'dsstudents', and the xml decrypted document is called 'encrypteddoc'.

the second function you specified, if I understand, loads the data set into a dataset called 'loaddataset', correct How do I call the function in that case

thank you VERY much for your help,

Dror.





Re: ASMX Web Services and XML Serialization XML into DATASET

rfreire

Dror,

Both functions returns a DataSet that you can assign to your dsstudents variable.

The LoadDataSet is an overloaded method that can receive either a string with the decrypted data as a string and the second can receive a XmlDocument object with the decrypted data as a DOM object. The second one is just takes the XML from the XmlDocument as string and calls the first one.

Please note, that the function can ONLY receive either a string or a XmlDocument.... if 'encrypteddoc' is neither a string nor a XmlDocument you'll get an error.

Please post a little bit more of your code so I can understand your problem.

Regards,

Rodrigo





Re: ASMX Web Services and XML Serialization XML into DATASET

miscal

there's my code:

'get input from encrypted XML

'decrypt XML file

Dim encryptedDoc As New XmlDocument()

encryptedDoc.Load("account.xml")

ProgressBar1.Value = 40

Dim encryptedElement As XmlElement = CType(encryptedDoc.GetElementsByTagName("EncryptedData")(0), XmlElement)

Dim ed2 As New EncryptedData()

ed2.LoadXml(encryptedElement)

Dim exml2 As New EncryptedXml()

'decrypt

Dim tDESkey As New TripleDESCryptoServiceProvider()

tDESkey.Key = Convert.FromBase64String("A5k5mAkl5lNe9hKJ875/LKtr5abh0kfh")

Dim decryptedBilling As Byte() = exml2.DecryptData(ed2, tDESkey)

exml2.ReplaceData(encryptedElement, decryptedBilling)

tDESkey.Clear() 'clear key

'verify the account details according the accounts retrieved from XML

Dim dsstudents As DataSet = New DataSet() 'define a new dataset

'***********************TODO: load the xml data from 'encrypteddoc' to 'dssturdents' dataset

'****************************************************************

ProgressBar1.Value = 50

Dim desiredrow As DataRow 'the desired row for the desired usernamer

Dim dtstudents As DataTable 'defining datatable