473,395 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

converting the xml to string

Hi Everyone,

I am constructing an xml file, but when I try to read it there are some
extra slashes in the output. Can anoyone tell me why there are some extra
slashed and can i send the file to web service with those extra slashes.
below I am constructing the document
StringWriter sWriter;
SqlDataReader dr;

dr = SqlHelper.ExecuteReader(connectionString,"SP_Users Data_Get");
XmlTextWriter w;
sWriter = new StringWriter();
//w = new XmlTextWriter("C:/text.txt", System.Text.Encoding.UTF8);
w= new XmlTextWriter(sWriter);

w.Formatting=Formatting.Indented;
w.Indentationfiltered=2;
w.WriteStartDocument(true);
w.WriteStartElement("test");
w.WriteStartElement("system");
w.WriteAttributeString("id", "UML");
w.WriteElementString("version", "1.0");
w.WriteStartElement("configuration");
w.WriteElementString("update_password","True");
w.WriteEndElement();
w.WriteStartElement("users");
while(dr.Read())
{
w.WriteStartElement("user");
w.WriteElementString("firstname", dr["first_name"].ToString());
w.WriteElementString("lastname", dr["last_name"].ToString());
w.WriteElementString("email", dr["email"].ToString());
w.WriteElementString("loginid", dr["Login"].ToString());

w.WriteElementString("status", "A");
w.WriteStartElement("roles");
w.WriteStartElement("role");
w.WriteString("Agent");
w.WriteStartElement("groups");
w.WriteStartElement("group");
w.WriteElementString("path", "Services/irvine/" +
dr["supervisor"].ToString());
w.WriteEndElement();
w.WriteEndElement();
w.WriteEndElement();
w.WriteEndElement();
w.WriteStartElement("relations");
w.WriteStartElement("relation");
w.WriteElementString("type", "UML");
w.WriteElementString("externalid", dr["Login"].ToString());
w.WriteEndElement();
w.WriteEndElement();
w.WriteEndElement();
}
w.WriteEndElement();
w.WriteEndDocument();
w.Close();
}

When I do sWriter.ToString , It gives me an output file like below:
"<?xml versionfiltered=\"1.0\" encoding=\"utf-16\"
standalone=\"yes\"?>\r\n<a>\r\n <system id=\"UMA\">\r\n
<version>1.0</version>\r\n <configuration>\r\n
<update_password>True</update_password>\r\n </configuration>\r\n <users>\r\n
<user>\r\n <firstname>

This is not the full xml, but as you can see I have \r\n slashes all over my
output xml. can I send my xml to web service like this.

Thanks.

--
vinki
Aug 8 '06 #1
1 1556
Hey,

The '\r\n' are the symbols for new line, as you are finally packing with
XMLTextWriter class, these doesn't effect your file. Hence you can pass the
file to webservice, will not be a problem

To calrify you in details, better save that stream to a file on to the disk
and try to open it from IE. What do you see ?
--
Every thing is perfect, as long as you share!!!
"vinki" wrote:
Hi Everyone,

I am constructing an xml file, but when I try to read it there are some
extra slashes in the output. Can anoyone tell me why there are some extra
slashed and can i send the file to web service with those extra slashes.
below I am constructing the document
StringWriter sWriter;
SqlDataReader dr;

dr = SqlHelper.ExecuteReader(connectionString,"SP_Users Data_Get");
XmlTextWriter w;
sWriter = new StringWriter();
//w = new XmlTextWriter("C:/text.txt", System.Text.Encoding.UTF8);
w= new XmlTextWriter(sWriter);

w.Formatting=Formatting.Indented;
w.Indentationfiltered=2;
w.WriteStartDocument(true);
w.WriteStartElement("test");
w.WriteStartElement("system");
w.WriteAttributeString("id", "UML");
w.WriteElementString("version", "1.0");
w.WriteStartElement("configuration");
w.WriteElementString("update_password","True");
w.WriteEndElement();
w.WriteStartElement("users");
while(dr.Read())
{
w.WriteStartElement("user");
w.WriteElementString("firstname", dr["first_name"].ToString());
w.WriteElementString("lastname", dr["last_name"].ToString());
w.WriteElementString("email", dr["email"].ToString());
w.WriteElementString("loginid", dr["Login"].ToString());

w.WriteElementString("status", "A");
w.WriteStartElement("roles");
w.WriteStartElement("role");
w.WriteString("Agent");
w.WriteStartElement("groups");
w.WriteStartElement("group");
w.WriteElementString("path", "Services/irvine/" +
dr["supervisor"].ToString());
w.WriteEndElement();
w.WriteEndElement();
w.WriteEndElement();
w.WriteEndElement();
w.WriteStartElement("relations");
w.WriteStartElement("relation");
w.WriteElementString("type", "UML");
w.WriteElementString("externalid", dr["Login"].ToString());
w.WriteEndElement();
w.WriteEndElement();
w.WriteEndElement();
}
w.WriteEndElement();
w.WriteEndDocument();
w.Close();
}

When I do sWriter.ToString , It gives me an output file like below:
"<?xml versionfiltered=\"1.0\" encoding=\"utf-16\"
standalone=\"yes\"?>\r\n<a>\r\n <system id=\"UMA\">\r\n
<version>1.0</version>\r\n <configuration>\r\n
<update_password>True</update_password>\r\n </configuration>\r\n <users>\r\n
<user>\r\n <firstname>

This is not the full xml, but as you can see I have \r\n slashes all over my
output xml. can I send my xml to web service like this.

Thanks.

--
vinki
Aug 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Cyde Weys | last post by:
I'm currently working on converting a simulator program from Visual Basic 6.0 to Visual C++ .NET. I've figured out most of the stuff, but there's still one thing I haven't gotten to and I've never...
9
by: Edward Diener | last post by:
I received no answers about this the first time I posted, so I will try again. My inability to decipher an MSDN topic may find others who have the same inability and someone who can decipher and...
13
by: Paraic Gallagher | last post by:
Hi, This is my first post to the list, I hope somebody can help me with this problem. Apologies if it has been posted before but I have been internet searching to no avail. What I am trying...
3
by: Wallace | last post by:
Hai, Can anyone tell how to convert an object into string? Please help me.... urgent.. Thanx in advance...
4
by: gg9h0st | last post by:
i'm a newbie studying php. i was into array part on tutorial and it says i'll get an array having keys that from member variable's name by converting an object to array. i guessed "i can...
9
by: Terry | last post by:
I am converting (attempting) some vb6 code that makes vast use of interfaces. One of the major uses is to be able to split out Read-only access to an obect. Let me give you a simple (contrived)...
5
by: SMichal | last post by:
Hi, how can I parse string "? 20.000" to double ?
3
by: nvx | last post by:
Hi, I'm looking for a simple way to convert a Double to a String exactly the .ToString() does, except these two differences: - the number of decimals is given (rounding is applied if necessary),...
2
by: CoreyWhite | last post by:
Problem: You have numbers in string format, but you need to convert them to a numeric type, such as an int or float. Solution: You can do this with the standard library functions. The...
10
by: Hank Stalica | last post by:
I'm having this weird problem where my code does the following conversion from string to float: 27000000.0 -27000000.00 2973999.99 -29740000.00 2989999.13 -2989999.25 The number on the left...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.