Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 19th, 2008, 11:14 AM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to tusharkale
Default XML handling using C#

hi,

I want to read xml stored in database (nvarchar column) and mask some of the field (modify the data) of it and again stored the masked xml in other table. How can I achieve this in fastest and most efficient way using C#?


  #2 (permalink)  
Old June 19th, 2008, 11:16 AM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to tusharkale
Default

any doc/tutorial resources related to this would be helful.

thanks

  #3 (permalink)  
Old June 19th, 2008, 11:19 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Which database, SQL Server 2005 can probably handle all this server-side which would normally be the most efficient. Otherwise you can read the data using a SqlCommand and ExecuteXmlReader which can then be processed as a stream or via XSLT. Or if you want to be cutting edge you could also do this with LINQ to XML.

--

Joe (Microsoft MVP - XML)
  #4 (permalink)  
Old June 19th, 2008, 11:19 AM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to tusharkale
Default

xml is stored in ntext column.

  #5 (permalink)  
Old June 20th, 2008, 08:38 AM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to tusharkale
Default

SOmehow I am not able to get it.
I have a table with two columns. tbl1 (id int, xml_doc ntext)
data is stored in xml format in (xml_doc) ntext column.
here is code which I have written

    mySqlCommand.CommandText = "SELECT TOP 1 xml_doc from tbl1";
    mySqlConnection.Open();
    XmlReader myXmlReader = mySqlCommand.ExecuteXmlReader();
    myXmlReader.Read();
      while (!myXmlReader.EOF) {
        Response.Write(myXmlReader.ReadOuterXml());

What should be my command to select xml_doc? and how do I change one of the parameter and saved it again as xml in table.

Thanks for help!


  #6 (permalink)  
Old June 20th, 2008, 08:45 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

http://support.microsoft.com/kb/316016

ExecuteXmlReader is used for returning the results of an SQL XML query - you are not performing an SQL XML query - you are mealy performing a normal SQL query which just happens to return a text value which you know is XML.

Code:
mySqlCommand.CommandText = "SELECT TOP 1 xml_doc from tbl1";
mySqlConnection.Open();
SqlDataReader reader = mySqlCommand.ExecuteReader();
if( reader.Read() )
{
  Response.Write(reader.GetString(0));

  XmlDocument doc = new XmlDocument();
  doc.LoadXml(reader.GetString(0));
}
If you want to use ExecuteXmlReader the look into the "FOR XML" TSQL statements as mentioned in the above KB article.


/- Sam Judson : Wrox Technical Editor -/
  #7 (permalink)  
Old June 20th, 2008, 08:50 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Sam is correct but you still haven't answered the question I posed in first response.

--

Joe (Microsoft MVP - XML)
  #8 (permalink)  
Old June 20th, 2008, 08:54 AM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to tusharkale
Default

Hi thanks for reply.
When I tried using the info given on link u provided I am getting follwong error
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Switch from current encoding to specified encoding not supported. Error processing resource 'http://localhost:2308/Default....

<?xml version="1.0" encoding="utf-16"?><ISDA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http:...



And even if this problem gets solved, How do I modify one of value of node? and saved in database again.


  #9 (permalink)  
Old June 20th, 2008, 08:55 AM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to tusharkale
Default

YEs I am using sql server 2005 database.

  #10 (permalink)  
Old June 20th, 2008, 09:00 AM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to tusharkale
Default

Reading xml doc stored in ntext column is not my priority basically I want to mask (change some of the values of node in xml). So first reading xml file storing it somewhere modifying it n then updating database..if there is any other way of doing it that would also be fine.

I want to do this in an most efficient way.

Thanks.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Handling recursive XML Nodes using XSL RichaM XSLT 5 June 21st, 2005 02:45 PM
Crystal reports 10 XML handling ferozkhan BOOK: Professional Crystal Reports for VS.NET 3 May 27th, 2005 11:25 AM
Crystal reports 10 XML handling ferozkhan XML 1 August 25th, 2004 08:33 AM
Handling remote XML docs in ASP delbarcr XML 1 March 25th, 2004 11:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.