469,352 Members | 1,694 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

Backslash "\" is being added to XML Attributes, Is there a way to get rid off it?

I have not encountering this problem 'till I got VS.NET 2003. Check my xml
below how the backlash is added. I tried all possible ways to replace it but
nothing happens. Any help will greatly appreciated.

<SESSION_INFO_ID ID=\"434674640\">
<TEL_NBR VALUE=\"2532668900\">
<PRODUCT hcid=\"1600\"></PRODUCT>
<PRODUCT hcid=\"1700\"></PRODUCT>
</TEL_NBR>
</SESSION_INFO_ID>
Nov 12 '05 #1
8 11529
Pete wrote:
I have not encountering this problem 'till I got VS.NET 2003. Check my xml
below how the backlash is added. I tried all possible ways to replace it but
nothing happens. Any help will greatly appreciated.

<SESSION_INFO_ID ID=\"434674640\">
<TEL_NBR VALUE=\"2532668900\">
<PRODUCT hcid=\"1600\"></PRODUCT>
<PRODUCT hcid=\"1700\"></PRODUCT>
</TEL_NBR>
</SESSION_INFO_ID>


Most likely that's visual effect produced by Visual Studio. It's
property inspector and debugging windows "feature".

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
As I said below I never encounter this in previous version. I used this xml
to pass to my stored procedure and due to that character it breaks the sp.

Here is the code snipet how I build the xml

StringWriter strWriter = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(strWriter);

writer.WriteAttributeString("session_info_id", "434674640");

.......

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:OG**************@tk2msftngp13.phx.gbl...
Pete wrote:
I have not encountering this problem 'till I got VS.NET 2003. Check my xml below how the backlash is added. I tried all possible ways to replace it but nothing happens. Any help will greatly appreciated.

<SESSION_INFO_ID ID=\"434674640\">
<TEL_NBR VALUE=\"2532668900\">
<PRODUCT hcid=\"1600\"></PRODUCT>
<PRODUCT hcid=\"1700\"></PRODUCT>
</TEL_NBR>
</SESSION_INFO_ID>


Most likely that's visual effect produced by Visual Studio. It's
property inspector and debugging windows "feature".

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #3
Pete wrote:
As I said below I never encounter this in previous version. I used this xml
to pass to my stored procedure and due to that character it breaks the sp.

Here is the code snipet how I build the xml

StringWriter strWriter = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(strWriter);

writer.WriteAttributeString("session_info_id", "434674640");


I don't believe this code produces that XML with slashes. As I said most
likely that's visual effect - there are no slashes in XML, but Visual
Studio .NET has a "feature" of showing slashes before quotes in property
inspector and debug windows.
Make sure there are really those slashes in XML - output it to console
or file.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #4
I don't want to argue with you but have you tried that class and writing
attributes?

Even my xsl transformation wouldn't recognize this crap.

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:e3**************@TK2MSFTNGP10.phx.gbl...
Pete wrote:
As I said below I never encounter this in previous version. I used this xml to pass to my stored procedure and due to that character it breaks the sp.
Here is the code snipet how I build the xml

StringWriter strWriter = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(strWriter);

writer.WriteAttributeString("session_info_id", "434674640");


I don't believe this code produces that XML with slashes. As I said most
likely that's visual effect - there are no slashes in XML, but Visual
Studio .NET has a "feature" of showing slashes before quotes in property
inspector and debug windows.
Make sure there are really those slashes in XML - output it to console
or file.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #5
Pete wrote:
I don't want to argue with you but have you tried that class and writing
attributes?
Well, have I tried XmlTextWriter? Sure :) It writes wellformed XML with
no backslashes whatsoever. It's a class from System.Xml namespace, you
can trust it.
Provide more info, may be reproducible sample etc. Should be some silly
error somewhere.
Even my xsl transformation wouldn't recognize this crap.


What do you mean exactly? Any exceptions?

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #6
Put this in your aspx.
StringWriter strWriter = new StringWriter();

XmlTextWriter writer = new XmlTextWriter(strWriter);

writer.WriteStartElement("SESSION_INFO_ID");

writer.WriteStartElement("TEL_NBR");

writer.WriteAttributeString("VALUE=","4258009000"

writer.WriteAttributeString("EXTN=","9000");

writer.WriteAttributeString("NAME=","Oleg Tkachenko XML MVP")

writer.WriteEndElement();

writer.WriteEndElement();

string input = strWriter.ToString();

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:uZ**************@TK2MSFTNGP10.phx.gbl...
Pete wrote:
I don't want to argue with you but have you tried that class and writing
attributes?


Well, have I tried XmlTextWriter? Sure :) It writes wellformed XML with
no backslashes whatsoever. It's a class from System.Xml namespace, you
can trust it.
Provide more info, may be reproducible sample etc. Should be some silly
error somewhere.
Even my xsl transformation wouldn't recognize this crap.


What do you mean exactly? Any exceptions?

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #7
Pete wrote:
Put this in your aspx.
Here is the result:

<SESSION_INFO_ID><TEL_NBR VALUE=="4258009000" EXTN=="9000" NAME=="Oleg
Tkachenko XML MVP" /></SESSION_INFO_ID>

No backslashes. Well, those == is definitely not well-formed. That's
known limitation of XmlTextWriter - it doesn't check names for validity.
See
http://msdn.microsoft.com/library/en...asp?frame=true
writer.WriteAttributeString("EXTN=","9000");
This is obviously wrong. First argument of WriteAttributeString is "The
local name of the attribute". Use
writer.WriteAttributeString("EXTN","9000");
writer.WriteEndElement();


Here you better close XmlTextWriter to flush the content:

writer.Close();
--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #8
Thanks!!

I run a profiler and the xml passes to the sp doesn't have backslashes. You
were right it was just a visual effect.

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:ua**************@TK2MSFTNGP11.phx.gbl...
Pete wrote:
Put this in your aspx.
Here is the result:

<SESSION_INFO_ID><TEL_NBR VALUE=="4258009000" EXTN=="9000" NAME=="Oleg
Tkachenko XML MVP" /></SESSION_INFO_ID>

No backslashes. Well, those == is definitely not well-formed. That's
known limitation of XmlTextWriter - it doesn't check names for validity.
See

http://msdn.microsoft.com/library/en...omizedxmlwrite
rcreation.asp?frame=true
writer.WriteAttributeString("EXTN=","9000");


This is obviously wrong. First argument of WriteAttributeString is "The
local name of the attribute". Use
writer.WriteAttributeString("EXTN","9000");
writer.WriteEndElement();


Here you better close XmlTextWriter to flush the content:

writer.Close();
--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Paul Miller | last post: by
134 posts views Thread by James A. Donald | last post: by
2 posts views Thread by Johann Blake | last post: by
19 posts views Thread by Alan J. Flavell | last post: by
45 posts views Thread by Umesh | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.