Groups | Blog | Home
all groups > dotnet xml > may 2004 >

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


Pete
5/4/2004 10:37:48 AM
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>

Pete
5/4/2004 12:02:34 PM
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");

.......



[quoted text, click to view]

Pete
5/4/2004 1:01:08 PM
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.

[quoted text, click to view]

Oleg Tkachenko [MVP]
5/4/2004 6:45:57 PM
[quoted text, click to view]

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

--
Oleg Tkachenko [XML MVP]
Pete
5/4/2004 6:58:09 PM
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();



[quoted text, click to view]

Oleg Tkachenko [MVP]
5/4/2004 8:31:14 PM
[quoted text, click to view]

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]
Oleg Tkachenko [MVP]
5/4/2004 9:18:19 PM
[quoted text, click to view]

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.

[quoted text, click to view]

What do you mean exactly? Any exceptions?

--
Oleg Tkachenko [XML MVP]
Pete
5/5/2004 9:09:39 AM
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.

[quoted text, click to view]
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcustomizedxmlwrite
rcreation.asp?frame=true
[quoted text, click to view]

Oleg Tkachenko [MVP]
5/5/2004 10:00:49 AM
[quoted text, click to view]

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-us/cpguide/html/cpconcustomizedxmlwritercreation.asp?frame=true

[quoted text, click to view]

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

[quoted text, click to view]

Here you better close XmlTextWriter to flush the content:

writer.Close();
--
Oleg Tkachenko [XML MVP]
AddThis Social Bookmark Button