100% found this document useful (1 vote)
91 views

Linq

The document contains XML code representing two XML files - Products.xml and Users.xml containing product and user data respectively. It also contains XQuery code to perform inner and outer joins on the two XML files and display the results. It further contains code snippets to add, update and delete rows from the XML file and encrypt/decrypt the XML data using TripleDES algorithm. It also shows an XSL stylesheet to transform the XML data and display it in HTML table format.

Uploaded by

api-3709520
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
91 views

Linq

The document contains XML code representing two XML files - Products.xml and Users.xml containing product and user data respectively. It also contains XQuery code to perform inner and outer joins on the two XML files and display the results. It further contains code snippets to add, update and delete rows from the XML file and encrypt/decrypt the XML data using TripleDES algorithm. It also shows an XSL stylesheet to transform the XML data and display it in HTML table format.

Uploaded by

api-3709520
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Xquery

Products.xml Users.xml
<?xml version="1.0" standalone="yes"?> <?xml version="1.0" standalone="yes"?>
<NewDataSet> <NewDataSet>
<Table> <Table>
<ItemID>1</ItemID> <userId>1</userId>
<UserID>1</UserID> <firstName>Sunil</firstName>
<ProductName>SOAP</ProductName> <lastName>krishna</lastName>
<Price>50</Price> <companyName>Assyst</companyName>
</Table> </Table>
<Table> <Table>
<ItemID>2</ItemID> <userId>2</userId>
<UserID>2</UserID> <firstName>JOMY</firstName>
<ProductName>BOOK</ProductName> <lastName>krishna</lastName>
<Price>40</Price> <companyName>Assyst</companyName>
</Table> </Table>
<Table> <Table>
<ItemID>3</ItemID> <userId>3</userId>
<UserID>3</UserID> <firstName>ANAS</firstName>
<ProductName>PEN</ProductName> <lastName>krishna</lastName>
<Price>50</Price> <companyName>Assyst</companyName>
</Table> </Table>
<Table> <Table>
<ItemID>4</ItemID> <userId>4</userId>
<UserID>5</UserID> <firstName>Aneesh</firstName>
<ProductName>PENCIL</ProductName> <lastName> </lastName>
<Price>50</Price> <companyName> </companyName>
</Table> </Table>
</NewDataSet> </NewDataSet>

Dim col As New XQueryNavigatorCollection()


col.AddNavigator("tbl_users.xml", "Users")
col.AddNavigator("Products.xml", "Products")
Dim ds As New DataSet
Dim query_outer As String
Dim query_innerjoin As String

Dim doc2 As New XmlDocument

query_innerjoin = "for $u in document(""Users"")//Table , $p in


document(""Products"")//Table " & _
"where $u/userId = $p/UserID " & _
"return <li> {$u/firstName , $p/ProductName} </li> " ''''inner join
Dim expr As New XQueryExpression(query_innerjoin)
Dim rawXML As String = "<Results> " & (expr.Execute(col)).ToXml() & " </Results> "

''''Outer join in hierrarichial view style


query_outer = "for $p in document(""Products"")//Table " & _
"return <Product> {$p/ProductName} " & _
"{ for $u in document(""Users"")//Table " & _
" where $p/UserID =$u/userId " & _
"return <user> {$p/ProductName} {$u/firstName} </user> } </Product> "

''''Outer join in normal style


query_outer = "for $p in document(""Products"")//Table " & _
"return <Product> {$p/ProductName} " & _
"{ for $u in document(""Users"")//Table " & _
" where $p/UserID =$u/userId " & _
"return $u/firstName } </Product> "

Dim expr1 As New XQueryExpression(query_outer)


Dim rawXML1 As String = "<Results> " & (expr1.Execute(col)).ToXml() & " </Results> "

doc2.LoadXml(rawXML1)
ds.ReadXml(New XmlNodeReader(doc2))
GridData.DataSource = ds
ADD ROW IN XML
Dim ds As New DataSet
strpath = "tbl_users.xml"
xmlDoc.Load(strpath)

Dim row As XmlNode = xmlDoc.SelectSingleNode("NewDataSet/Table[userId='2']")

Dim parent As XmlNode = xmlDoc.SelectSingleNode("NewDataSet/Table[userId='2']").ParentNode

row = row.CloneNode(True) '' make a copy of the node by cloning it


row.SelectSingleNode("userId").InnerText = parent.ChildNodes.Count + 1
row("firstName").InnerText = TxtBox2.Text '' set the new values of the row’s fields
row("lastName").InnerText = TxtBox3.Text
row("companyName").InnerText = TxtBox4.Text
row("userName").InnerText = TxtBox4.Text
row("password").InnerText = TxtBox5.Text

'' append the cloned row to the parent node

parent.AppendChild(row)
TxtBox1.Text = parent.ChildNodes.Count

xmlDoc.Save(strpath)
ds.ReadXml(strpath)
GridData.DataSource = ds

UPDATION IN XML
Dim loNode As XmlNode
xmlDoc.Load(strpath)
Dim intId As Integer
intId = GridData.Selected.Rows(0).Cells(0).Text
TxtBox1.Text = intId
loNode = xmlDoc.SelectSingleNode("NewDataSet/Table[userId='" & TxtBox1.Text & "']")

loNode("userId").InnerText = Val(TxtBox1.Text)
loNode("firstName").InnerText = TxtBox2.Text '' set the new values of the row’s fields
loNode("lastName").InnerText = TxtBox3.Text
loNode("companyName").InnerText = TxtBox4.Text
loNode("userName").InnerText = TxtBox4.Text
loNode("password").InnerText = TxtBox5.Text
' ''Dim x = xmlDoc.GetElementsByTagName("lastName")
' ''MsgBox(loNode.InnerText)
' ''For i = 1 To x.Count - 1
' '' MsgBox(x.Item(i).InnerText)
' ''Next
xmlDoc.Save(strpath)
ds.ReadXml(strpath)
GridData.DataSource = ds

DELETION IN XML
strpath = "tbl_users.xml"
Dim ds As New DataSet
With GridData
Dim intId As Integer

intId = .Selected.Rows(0).Cells(0).Text
xmlDoc.Load(strpath)
Dim row As XmlNode = xmlDoc.SelectSingleNode("NewDataSet/Table[userId='" & intId & "']")

row.ParentNode.RemoveChild(row)
xmlDoc.Save(strpath)
ds.ReadXml(strpath)
GridData.DataSource = ds
End With

XML ENCRYPTION

Dim xmldoc As New XmlDocument()


Try
xmldoc.Load("D:\Aneesh k\xsl-test project\ToEncrypt.xml")
'xmldoc.Load("D:\ToQuery.xml")
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try

Dim tDESkey As New TripleDESCryptoServiceProvider()


Dim sElem As XmlElement = CType(xmldoc.SelectSingleNode("/NewDataSet"), XmlElement)
Dim exml As EncryptedXml = New EncryptedXml(xmldoc)
Dim encryptedArray As Byte() = exml.EncryptData(sElem, tDESkey, False)
Dim ed As New EncryptedData()
ed.Type = EncryptedXml.XmlEncElementUrl
ed.EncryptionMethod = New EncryptionMethod(EncryptedXml.XmlEncTripleDESUrl)
ed.CipherData = New CipherData()
ed.CipherData.CipherValue = encryptedArray
EncryptedXml.ReplaceElement(sElem, ed, True)
xmldoc.Save("D:\Aneesh k\xsl-test project\encrypted.xml")

Dim encryptedDoc As New XmlDocument()


encryptedDoc.Load("D:\Aneesh k\xsl-test project\encrypted.xml")
Dim encryptedElement As XmlElement =
CType(encryptedDoc.GetElementsByTagName("EncryptedData")(0), XmlElement)
Dim ed2 As New EncryptedData()
ed2.LoadXml(encryptedElement)
Dim exml2 As New EncryptedXml()
Dim decryptedBilling As Byte() = exml2.DecryptData(ed2, tDESkey)
MsgBox(tDESkey.ToString)
exml2.ReplaceData(encryptedElement, decryptedBilling)
encryptedDoc.Save("D:\Aneesh k\xsl-test project\Decrypted.xml")
End Sub

XSL
New1.xsl

<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"


xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">
<html>
<body>
<h2>USER LIST</h2>
<table border="1" Cellalign="center">
<tr bgcolor="#9acd32">
<th align="left">firstName</th>
<th align="left">lastName</th>
<th align="left">companyName</th>
<th align="left">emailAddress</th>
<th align="left">userName</th>
<th align="left">password</th>
<th align="left">createdDate</th>
<th align="left">createdBy</th>
<th align="left">status</th>
<th align="left">secretQuestion</th>
<th align="left">secretAnswer</th>
</tr>
<xsl:for-each select="NewDataSet/Table">
<tr>
<td><xsl:value-of select="firstName"/></td>
<td><xsl:value-of select="lastName"/></td>
<td><xsl:value-of select="companyName"/></td>
<td><xsl:value-of select="emailAddress"/></td>
<td><xsl:value-of select="userName"/></td>
<td><xsl:value-of select="password"/></td>
<td><xsl:value-of select="createdDate"/></td>
<td><xsl:value-of select="createdBy"/></td>
<td><xsl:value-of select="status"/></td>
<td><xsl:value-of select="secretQuestion"/></td>
<td><xsl:value-of select="secretAnswer"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template></xsl:stylesheet>

New.xml

<?xml version="1.0" standalone="yes"?>


<?xml-stylesheet type="text/xsl" href="new1.xsl"?>
<NewDataSet>
<Table>
<userId>101</userId>
<firstName>aaa</firstName>
<lastName>fff</lastName>
<companyName>xxx</companyName>
<emailAddress>k.kkk@ppp</emailAddress>
.
.
.
Wb1.Navigate("D:\Aneesh k\xsl-test project\new.xml")

“””””””Stored procedure encryption

declare @encryptedstuff VARCHAR(100)


declare @MYText VARCHAR(100)
declare @decryptedstuff VARCHAR(100)

SET @MYText = 'ANEESH KUZHIKKATTIL'

SET @encryptedstuff = EncryptByPassPhrase('LED_PWD-2007', @MYText)


SELECT @encryptedstuff

SET @decryptedstuff = DecryptByPassPhrase('LED_PWD-2007', @encryptedstuff)


SELECT @decryptedstuff

You might also like