
August 9th, 2006, 12:25 AM
| | | 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 | 
August 9th, 2006, 08:55 AM
| | | RE: converting the xml to string
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: Quote:
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
| |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|