C# XML -> MSSQL Database

  • Thread starter Thread starter Pratik Parikh
  • Start date Start date
P

Pratik Parikh

Hi eveyone,

Hi EveryOne,

I am having a real problem, which i am unable to resolve.
The problem is that i am tring to convert the datset using
XmlDataDocument, following is the code. My Problem is that
the while assigning the InnerXml to string variable
stream. it add escape character to my xml stream. after
the code is the example...of xml output. A help will be
really appreciated



public void PostFeedbackResponseAsDataSet(ResponseDataSet
response,Int32 feedbackMaximumResponseSize)

{

try

{

String stream = "";



XmlDataDocument xmldom = new XmlDataDocument(response);



if(xmldom.HasChildNodes)

{

<!--Problem-->stream = xmldom.FirstChild.InnerXml.ToString
(); if(stream.Length > feedbackMaximumResponseSize)

{

throw(new ArgumentException("Feedback response exceeds
maximum allowed size for this feedback"));

}

DAL.InsertResponses(stream);

}

}

catch(Exception e)

{

Utility.Logger.WriteEntry(e.Message +"\t" + csStackTrace +
e.StackTrace);

throw(e);

}

}



<comment>
<FeedbackResponse Id=\"bca3180b-6e66-47f1-9ed1-
6acdfa8c986a\"
xmlns=\"http://tempuri.org/SampleResponse.xsd\"><Question
Id=\"1\" xmlns=\"\"><Answer Id=\"1\"
Text=\"dddddddddddddd\"></Answer></Question><Question
Id=\"2\" xmlns=\"\"><Answer Id=\"3
\"></Answer></Question><Question Id=\"3\"
xmlns=\"\"><Answer Id=\"5\"></Answer></Question><Question
Id=\"4\" xmlns=\"\"><Answer Id=\"14
\"></Answer></Question><Question Id=\"5\"
xmlns=\"\"><Answer Id=\"15\"></Answer><Answer Id=\"16
\"></Answer><Answer Id=\"17\"></Answer><Answer Id=\"18
\"></Answer><Answer Id=\"19\"></Answer><Answer Id=\"20
\"></Answer><Answer Id=\"21\"></Answer><Answer Id=\"22
\"></Answer><Answer Id=\"23\"></Answer><Answer Id=\"24
\"></Answer><Answer Id=\"25
\"></Answer></Question><Question Id=\"6\"
xmlns=\"\"><Answer Id=\"26\"></Answer><Answer Id=\"27
\"></Answer><Answer Id=\"28\"></Answer><Answer Id=\"29
\"></Answer><Answer Id=\"30\"></Answer><Answer Id=\"31
\"></Answer><Answer Id=\"32
\"></Answer></Question></FeedbackResponse>
</comment>
 
This is not a problem, it is the way it is supposed to work.
Search this NG for message with subject: "Unwanted Escape Codes In
String..."
 
Hi Friend,

A Question :

I have following xml:
<FeedbackResponse Id="bca3180b-6e66-47f1-9ed1-6acdfa8c986a"
xmlns="http://tempuri.org/SampleResponse.xsd">
<Question Id="1" xmlns="">
<Answer Id="1" Text="dddddddddddddd">
</Answer>
</Question>
<Question Id="2" xmlns="">
<Answer Id="3"></Answer>
</Question>
<Question Id="3" xmlns="">
<Answer Id="5"></Answer>
</Question>
<Question Id="4" xmlns="">
<Answer Id="12"></Answer>
</Question>
<Question Id="5" xmlns="">
<Answer Id="15"></Answer>
<Answer Id="16"></Answer>
<Answer Id="17"></Answer>
<Answer Id="18"></Answer>
</Question>
<Question Id="6" xmlns="">
<Answer Id="26"></Answer>
<Answer Id="27"></Answer>
<Answer Id="28"></Answer>
<Answer Id="29"></Answer>
</Question>
</FeedbackResponse>

I am having hardtime setting up the path, can any one help me with it...
here si my SQL SERVER STORED PROCEDURE And also please explain how you
figure out these stuff..

<code>

ALTER PROCEDURE InsertResponses
@XML nText
AS
SET NOCOUNT ON
SET XACT_ABORT ON
DECLARE @SessionId INT
print @XML
BEGIN TRANSACTION
DECLARE @idoc INT
EXECUTE sp_xml_preparedocument @idoc OUTPUT, @XML
SELECT [Id] FROM OPENXML (@idoc,'FeedbackResponse/',1)
EXECUTE sp_xml_removedocument @idoc
COMMIT TRANSACTION
RETURN 0
</code>
 
Back
Top