Loading XML in C#

S

sam

I have the following code that I am having issues with and I was wondering
if someone could explain to me why it's doing what it's doing:

strXML =
"<EngineDocList><DocVersion>1.0</DocVersion><TimeIn></TimeIn><TimeOut></TimeOut><EngineDoc><ContentType>OrderFormDoc</ContentType>";

strXML = strXML + "<User><Name></Name><Password></Password><ClientId
DataType='S32'></ClientId></User><Instructions><Pipeline>Payment</Pipeline></Instructions><OrderFormDoc>".ToString();

strXML = strXML +
"<Mode>Y</Mode><Id></Id><Transaction><Type>Void</Type></Transaction></OrderFormDoc></EngineDoc></EngineDocList>";

xmlDocument1.async = false;

xmlDocument1.loadXML (strXML);



When the document loads the XML it looks like the following: xml
"<EngineDocList><DocVersion>1.0</DocVersion><TimeIn></TimeIn><TimeOut></TimeOut><EngineDoc><ContentType>OrderFormDoc</ContentType><User><Name>N</Name><Password>N01</Password><ClientId
DataType=\"S32\">5367</ClientId></User><Instructions><Pipeline>Payment</Pipeline></Instructions><OrderFormDoc><Mode>Y</Mode><Id>20060809
091906MKhanks</Id><Transaction><Type>Void</Type></Transaction></OrderFormDoc></EngineDoc></EngineDocList>\r\n"
string


My problem is that the DataType now has a "\" in it \"S32\" How in the
heck do I get rid of them! I am new to c# and this code works fine in
VB.net.

Any help would be greatly appreciated.

Sam
 
J

John Saunders

Comments inline.


I have the following code that I am having issues with and I was wondering
if someone could explain to me why it's doing what it's doing:

strXML =
"<EngineDocList><DocVersion>1.0</DocVersion><TimeIn></TimeIn><TimeOut></TimeOut><EngineDoc><ContentType>OrderFormDoc</ContentType>";

strXML = strXML + "<User><Name></Name><Password></Password><ClientId
DataType='S32'></ClientId></User><Instructions><Pipeline>Payment</Pipeline></Instructions><OrderFormDoc>".ToString();


You don't need .ToString(). It's already a string.
strXML = strXML +
"<Mode>Y</Mode><Id></Id><Transaction><Type>Void</Type></Transaction></OrderFormDoc></EngineDoc></EngineDocList>";

xmlDocument1.async = false;

xmlDocument1.loadXML (strXML);


Why are you using the MSXML DOM instead of the .NET Framework classes, like
XmlDocument?
When the document loads the XML it looks like the following: xml
"<EngineDocList><DocVersion>1.0</DocVersion><TimeIn></TimeIn><TimeOut></TimeOut><EngineDoc><ContentType>OrderFormDoc</ContentType><User><Name>N</Name><Password>N01</Password><ClientId
DataType=\"S32\">5367</ClientId></User><Instructions><Pipeline>Payment</Pipeline></Instructions><OrderFormDoc><Mode>Y</Mode><Id>20060809
091906MKhanks</Id><Transaction><Type>Void</Type></Transaction></OrderFormDoc></EngineDoc></EngineDocList>\r\n"
string


My problem is that the DataType now has a "\" in it \"S32\" How in the
heck do I get rid of them! I am new to c# and this code works fine in
VB.net.

How did you determine that the string had \" in it? By looking in the
debugger?

The debugger is showing you a representation of the string as it would have
to be typed in to a C# program. The \" aren't really there.

John
 
S

sam

The reason I am using MSXML is that I was given the VB code and told to get
it working in C#. Since it was working in VB I figured that I would just
continue using it. As for the "\", I know that it is adding it because I
get the same message returned it I copy the string with the dash and put it
in the XML compiler that we have. If I take out the dash it works just
fine.

I also tried to use the XMLDocument but can't find out how to add the
DataType throught this also. I tried searching google for datatype code but
have had 0 luck!

myXmlTextWriter.WriteStartElement("User");
myXmlTextWriter.WriteElementString("Name", "N");
myXmlTextWriter.WriteElementString("Password", "N01");
myXmlTextWriter.WriteStartElement("ClientId");
myXmlTextWriter.WriteElementString("ClientId","5367"); // Need a dataset of
S32
//myXmlTextWriter.WriteElementString("DataType", "S32");
//myXmlTextWriter.WriteElementString("5367", "");
myXmlTextWriter.WriteEndElement();



"John Saunders" <john.saunders at trizetto.com> wrote in message
 
M

Michael Feingold

Are you sure you are not fighting ghosts? The string in your post looks
suspiciously like it was taken from the watch or something
If this is the case what you see there is how all these windows show you a
double-quote. So all what is happening to your string
single quotes replaced with double quotes

As to writing it with the XmlReader you have to write S36 as an attribute
(i.e. WriteAttributeString(..))
 
S

sam

Ok, so I think I pretty much have everything licked in this but I am just
having 1 more issue. It seems that xml version is not needed in my string
and is throwing everything off. If I remove it then it in our XML tester it
works just fine. It is also not there when I run in VB. "<?xml
version='1.0' encoding='utf-16' standalone='no'?>. Is there an option to
not include this?

Sam


message news:[email protected]...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,813
Messages
2,569,699
Members
45,489
Latest member
SwethaJ

Latest Threads

Top