C# XML -> MSSQL Database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pratik Parikh

    #1

    C# XML -> MSSQL Database

    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 PostFeedbackRes ponseAsDataSet( ResponseDataSet
    response,Int32 feedbackMaximum ResponseSize)

    {

    try

    {

    String stream = "";



    XmlDataDocument xmldom = new XmlDataDocument (response);



    if(xmldom.HasCh ildNodes)

    {

    <!--Problem-->stream = xmldom.FirstChi ld.InnerXml.ToS tring
    (); if(stream.Lengt h > feedbackMaximum ResponseSize)

    {

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

    }

    DAL.InsertRespo nses(stream);

    }

    }

    catch(Exception e)

    {

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

    throw(e);

    }

    }



    <comment>
    <FeedbackRespon se Id=\"bca3180b-6e66-47f1-9ed1-
    6acdfa8c986a\"
    xmlns=\"http://tempuri.org/SampleResponse. xsd\"><Question
    Id=\"1\" xmlns=\"\"><Ans wer Id=\"1\"
    Text=\"dddddddd dddddd\"></Answer></Question><Quest ion
    Id=\"2\" xmlns=\"\"><Ans wer Id=\"3
    \"></Answer></Question><Quest ion Id=\"3\"
    xmlns=\"\"><Ans wer Id=\"5\"></Answer></Question><Quest ion
    Id=\"4\" xmlns=\"\"><Ans wer Id=\"14
    \"></Answer></Question><Quest ion Id=\"5\"
    xmlns=\"\"><Ans wer 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><Quest ion Id=\"6\"
    xmlns=\"\"><Ans wer 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></FeedbackRespons e>
    </comment>
  • codewriter

    #2
    Re: C# XML -&gt; MSSQL Database

    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..."

    "Pratik Parikh" <pratik.parikh@ inin.com> wrote in message
    news:146001c35b 9e$d1e6a560$7d0 2280a@phx.gbl.. .[color=blue]
    > 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 PostFeedbackRes ponseAsDataSet( ResponseDataSet
    > response,Int32 feedbackMaximum ResponseSize)
    >
    > {
    >
    > try
    >
    > {
    >
    > String stream = "";
    >
    >
    >
    > XmlDataDocument xmldom = new XmlDataDocument (response);
    >
    >
    >
    > if(xmldom.HasCh ildNodes)
    >
    > {
    >
    > <!--Problem-->stream = xmldom.FirstChi ld.InnerXml.ToS tring
    > (); if(stream.Lengt h > feedbackMaximum ResponseSize)
    >
    > {
    >
    > throw(new ArgumentExcepti on("Feedback response exceeds
    > maximum allowed size for this feedback"));
    >
    > }
    >
    > DAL.InsertRespo nses(stream);
    >
    > }
    >
    > }
    >
    > catch(Exception e)
    >
    > {
    >
    > Utility.Logger. WriteEntry(e.Me ssage +"\t" + csStackTrace +
    > e.StackTrace);
    >
    > throw(e);
    >
    > }
    >
    > }
    >
    >
    >
    > <comment>
    > <FeedbackRespon se Id=\"bca3180b-6e66-47f1-9ed1-
    > 6acdfa8c986a\"
    > xmlns=\"http://tempuri.org/SampleResponse. xsd\"><Question
    > Id=\"1\" xmlns=\"\"><Ans wer Id=\"1\"
    > Text=\"dddddddd dddddd\"></Answer></Question><Quest ion
    > Id=\"2\" xmlns=\"\"><Ans wer Id=\"3
    > \"></Answer></Question><Quest ion Id=\"3\"
    > xmlns=\"\"><Ans wer Id=\"5\"></Answer></Question><Quest ion
    > Id=\"4\" xmlns=\"\"><Ans wer Id=\"14
    > \"></Answer></Question><Quest ion Id=\"5\"
    > xmlns=\"\"><Ans wer 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><Quest ion Id=\"6\"
    > xmlns=\"\"><Ans wer 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></FeedbackRespons e>
    > </comment>[/color]


    Comment

    • Pratik Parikh

      #3
      Re: C# XML -&gt; MSSQL Database

      Hi Friend,

      A Question :

      I have following xml:
      <FeedbackRespon se Id="bca3180b-6e66-47f1-9ed1-6acdfa8c986a"
      xmlns="http://tempuri.org/SampleResponse. xsd">
      <Question Id="1" xmlns="">
      <Answer Id="1" Text="ddddddddd ddddd">
      </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>
      </FeedbackRespons e>

      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_prepared ocument @idoc OUTPUT, @XML
      SELECT [Id] FROM OPENXML (@idoc,'Feedbac kResponse/',1)
      EXECUTE sp_xml_removedo cument @idoc
      COMMIT TRANSACTION
      RETURN 0
      </code>

      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      Working...