Escape codes embedded in XML

Hello,

I have built an XMLDocument object instance and I get the following string
when I examine the InnerXml property:

<?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1
QID=\"55111\"><Tag2 AID=\"5511101\"></Tag2></Tag1><Tag1 QID=\"55112\"><Tag2
AID=\"5511217\"></Tag2></Tag1><Tag1 QID=\"5512282\"><Tag2
AID=\"551228206\"></Tag2></Tag1><Tag1 QID=\"55114\"><Tag2
AID=\"5511406\"></Tag2></Tag1><Tag1 QID=\"55115\"><Tag2
AID=\"5511505\"></Tag2></Tag1></UserData></ROOT>

Notice that the double quotes are all escaped--that is they appear as

\"

versus

"

I would like to "transform" or "convert" this string into a string in which
the escape characters are "converted". This would generate a string that
would appear like this:

<?xml version="1.0"?><ROOT><UserData UserID="2282"><Tag1 QID="55111"><Tag2
AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Tag2
AID="5511217"></Tag2></Tag1><Tag1 QID="5512282"><Tag2
AID="551228206"></Tag2></Tag1><Tag1 QID="55114"><Tag2
AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Tag2
AID="5511505"></Tag2></Tag1></UserData></ROOT>

I do not want to use a search/replace algorithm because I cannot be entirely
sure that there will not be escape sequences other than \" in the string. I
am actually seeking a solution that would "transform" the \" to " (as I
require) but also one that would convert \n to ASCII 10 and \r to ASCII 13.
In other words, I would like to convert the escape-encoded string to a
standard ASCII string.

Moreover, why does the XMLDocument's InnerXml return an escape-encoded
string instead of a "straight" (unencoded) string? Is there a way to get the
InnerXml to return the "straight" string? I plan to pass the XML string as
an argument to a Sql stored procedure; therefore, the encoded string does
not work--I must use the unencoded version. Certainly others have
encountered this problem--I just could not find a single solution and I
spend hours searching MSDN and Google! For example, I read some other
threads that suggest using ActiveXMessageFormatter, but not one of them
actually explained how to do it--and pseudocode can only be so useful...

Thank you in advance for any assistance. I will confirm whether any
suggestions work.

Regards,
Steve





0
8/2/2003 5:45:53 PM
dotnet.xml 7266 articles. 0 followers. Follow

5 Replies
690 Views

Similar Articles

[PageSpeed] 3

I don't believe the System.Xml.XmlDocument class should behave in the way
you describe. How are you constructing this XML and how are you displaying
it?


--
This posting is provided "AS IS" with no warranties, and confers no rights.

"Steve Litvack" <usa_NO8SPAM004@yahoo.com> wrote in message
news:lNSWa.146101$xg5.117864@twister.austin.rr.com...
> Hello,
>
> I have built an XMLDocument object instance and I get the following string
> when I examine the InnerXml property:
>
> <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1
> QID=\"55111\"><Tag2 AID=\"5511101\"></Tag2></Tag1><Tag1
QID=\"55112\"><Tag2
> AID=\"5511217\"></Tag2></Tag1><Tag1 QID=\"5512282\"><Tag2
> AID=\"551228206\"></Tag2></Tag1><Tag1 QID=\"55114\"><Tag2
> AID=\"5511406\"></Tag2></Tag1><Tag1 QID=\"55115\"><Tag2
> AID=\"5511505\"></Tag2></Tag1></UserData></ROOT>
>
> Notice that the double quotes are all escaped--that is they appear as
>
> \"
>
> versus
>
> "
>
> I would like to "transform" or "convert" this string into a string in
which
> the escape characters are "converted". This would generate a string that
> would appear like this:
>
> <?xml version="1.0"?><ROOT><UserData UserID="2282"><Tag1 QID="55111"><Tag2
> AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Tag2
> AID="5511217"></Tag2></Tag1><Tag1 QID="5512282"><Tag2
> AID="551228206"></Tag2></Tag1><Tag1 QID="55114"><Tag2
> AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Tag2
> AID="5511505"></Tag2></Tag1></UserData></ROOT>
>
> I do not want to use a search/replace algorithm because I cannot be
entirely
> sure that there will not be escape sequences other than \" in the string.
I
> am actually seeking a solution that would "transform" the \" to " (as I
> require) but also one that would convert \n to ASCII 10 and \r to ASCII
13.
> In other words, I would like to convert the escape-encoded string to a
> standard ASCII string.
>
> Moreover, why does the XMLDocument's InnerXml return an escape-encoded
> string instead of a "straight" (unencoded) string? Is there a way to get
the
> InnerXml to return the "straight" string? I plan to pass the XML string as
> an argument to a Sql stored procedure; therefore, the encoded string does
> not work--I must use the unencoded version. Certainly others have
> encountered this problem--I just could not find a single solution and I
> spend hours searching MSDN and Google! For example, I read some other
> threads that suggest using ActiveXMessageFormatter, but not one of them
> actually explained how to do it--and pseudocode can only be so useful...
>
> Thank you in advance for any assistance. I will confirm whether any
> suggestions work.
>
> Regards,
> Steve
>
>
>
>
>


0
dareo (72)
8/3/2003 1:13:27 AM
Why

  string s = Convert.ToString(xmlAnswers.InnerXml);

and not

string s = xmlAnswers.InnerXml;

--
This posting is provided "AS IS" with no warranties, and confers no rights.

"Steve Litvack" <usa_NO8SPAM004@yahoo.com> wrote in message
news:JCZWa.148375$xg5.85484@twister.austin.rr.com...
> Yes--I was surprised myself. Thank you--you may be able to help!
>
> Here is my code (note that even the XML Declaration ends up with the
escaped
> quotes--so it's not just limited to data coming from the ButtonList
control
> embedded in a DataGrid):
>
> In the code below, I build the XML Document and then set the result to
> string s.
> s then contains the XML text I showed--the text that contains the escape
> codes...
>
> See below, and thanks again.
>
> --Steve
>
> // save the survey answers as an XML Document (XMLAnswers)
> XmlDocument xmlAnswers;
> XmlNode xmlNode, xmlAttribute;
> XmlElement xmlElem, xmlElem2, xmlElem3;
> XmlText xmlText;
>
> // <ROOT>
> xmlAnswers = new XmlDocument();
>
> // add the XML declaration section
> xmlNode = xmlAnswers.CreateNode(XmlNodeType.XmlDeclaration,"","");
> xmlAnswers.AppendChild(xmlNode);
>
> // add the root element
> xmlElem = xmlAnswers.CreateElement("","ROOT","");
>
> // xmltext=xmldoc.CreateTextNode("This is the text of the root element");
> xmlText = xmlAnswers.CreateTextNode("");
> xmlElem.AppendChild(xmlText);
> xmlAnswers.AppendChild(xmlElem);
>
>
> // <PROFILE> tag
> // add another element (child of the root)
> xmlElem = xmlAnswers.CreateElement("","Profile","");
>
> // xmltext=xmldoc.CreateTextNode("The text of the sample element");
> xmlText = xmlAnswers.CreateTextNode("");
> xmlElem.AppendChild(xmlText);
>
> // <PROFILE UserID> attribute
> xmlAttribute = xmlAnswers.CreateNode(XmlNodeType.Attribute,"UserID","");
> xmlAttribute.Value =
> ((SiteIdentity)Context.User.Identity).UserID.ToString();
> xmlElem.Attributes.Append((System.Xml.XmlAttribute)xmlAttribute);
>
> // loop through questions
> System.Web.UI.WebControls.DataGridItemCollection dgCollection =
> this.dgrdQuestions.Items;
> foreach (System.Web.UI.WebControls.DataGridItem dgItem in dgCollection)
> {
>     // get the buttonlist object so that we can inspect the SelectedValue
>     System.Web.UI.WebControls.RadioButtonList ButtonList;
>     ButtonList =
>
(System.Web.UI.WebControls.RadioButtonList)(dgItem.FindControl("radlstAnswer
> s"));
>
>     // <QUESTION> tag
>     xmlElem2 = xmlAnswers.CreateElement("","Question","");
>     xmlText = xmlAnswers.CreateTextNode("");
>     xmlElem2.AppendChild(xmlText);
>
>     // <QUESTION PrQuID> attribute
>     xmlAttribute =
xmlAnswers.CreateNode(XmlNodeType.Attribute,"PrQuID","");
>     xmlAttribute.Value = dgItem.Cells[2].Text;
>     xmlElem2.Attributes.Append((System.Xml.XmlAttribute)xmlAttribute);
>
>     // <ANSWER> tag
>     // add another element (child of the root)
>     xmlElem3 = xmlAnswers.CreateElement("","Answer","");
>
>     // xmltext=xmldoc.CreateTextNode("The text of the sample element");
>     xmlText = xmlAnswers.CreateTextNode("");
>     xmlElem3.AppendChild(xmlText);
>
>     // <ANSWER PrAnID> attribute
>     xmlAttribute =
xmlAnswers.CreateNode(XmlNodeType.Attribute,"PrAnID","");
>     xmlAttribute.Value = ButtonList.SelectedValue.ToString();
>     xmlElem3.Attributes.Append((System.Xml.XmlAttribute)xmlAttribute);
>     xmlElem2.AppendChild(xmlElem3);
>
>     // add the question to the profile tag
>     xmlElem.AppendChild(xmlElem2);
>     // add the profile to the root tag
>     xmlAnswers.ChildNodes.Item(1).AppendChild(xmlElem);
> }
>
> string s = Convert.ToString(xmlAnswers.InnerXml);
>
>
>
>
> "Dare Obasanjo [MSFT]" <dareo@online.microsoft.com> wrote in message
> news:ujuZuxVWDHA.388@TK2MSFTNGP10.phx.gbl...
> > I don't believe the System.Xml.XmlDocument class should behave in the
way
> > you describe. How are you constructing this XML and how are you
displaying
> > it?
>
>


0
dareo (72)
8/3/2003 11:29:35 PM
Hi:

That really was an oversight--I originally had the version you suggestion
("string s = xmlAnswers.InnerXml") but was experimenting with other ways of
getting a string result in an effort to try to avoid getting those pesky
escape codes. My way and your way are returning the same string.

Any other ideas?

Regards,
Steve

"Dare Obasanjo [MSFT]" <dareo@online.microsoft.com> wrote in message
news:%23S3iUchWDHA.572@TK2MSFTNGP11.phx.gbl...
> Why
>
>   string s = Convert.ToString(xmlAnswers.InnerXml);
>
> and not
>
> string s = xmlAnswers.InnerXml;


0
8/4/2003 1:24:16 AM
Steve Litvack wrote:

> Any other ideas?
I can't reproduce the problem. Actually to be able to compile you code I had 
to comment out foreach loop, which gives me only
<?xml version="1.0"?><ROOT></ROOT>
But even that doesn't have nothing pesky.
-- 
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

0
oleg7603 (294)
8/4/2003 8:21:31 AM
I feel like a darn fool...

You're right: I was trying to debug Sql (the root cause was an XML case
issue), and used the watch window to observe my XML string. I have a VB
background, and in VB 6 and below you would never see a "VB representation"
of a string that does not match the actual output for the string (at least I
cannot think of an example; of course, an embedded low ASCII char, such as
Chr(10)--a linefeed char--could show a funky character when in a watch
window, but it would not be "escaped"). So C#'s representation of the string
IN THE WATCH WINDOW is what threw me because it shows the escape sequences!

I outputted the value with Response.Write(), and see that the text that
appears does, in fact, not have the escape sequences.

So, all along this was a red herring for me (XML case was the root cause).

Thanks to all for setting me straight.

Regards,
Steve
"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:eB2iDilWDHA.1004@TK2MSFTNGP12.phx.gbl...
> Steve Litvack wrote:
>
> > Any other ideas?
> I can't reproduce the problem. Actually to be able to compile you code I
had
> to comment out foreach loop, which gives me only
> <?xml version="1.0"?><ROOT></ROOT>
> But even that doesn't have nothing pesky.
> -- 
> Oleg Tkachenko
> http://www.tkachenko.com/blog
> Multiconn Technologies, Israel
>


0
8/4/2003 3:13:15 PM
Reply:

Similar Artilces:

Threading question
Is there a way to protect a section of code so that all the statements in the protected block are executed without being interrupted by another thread? I have a worker thread that adds a value to an array (a circular buffer) then increments the array index. If the user clicks on a button of a form in the main thread, sometimes the main thread code will then access the array after the value has been added, but before the array index has been updated. I know I've seen ways to protect code in other languages (Pascal or Ada I think) but how can this be done in vb.net? t...

Word 2007 embedded Chart data Fill or Autofill
Is it possible, using Word 2007, to perform a Fill or an Autofill operation on an embedded (unlinked) chart? The chart was created earlier within Word. Initially, I was thinking about the newer style, where two adjacent cells are populated, selected, then the Fill handle is dragged to the last cell of the Fill. I created a macro in excel, of which I pasted a portion to my word chart. After modifying the Range (as I understand is different in Word), I found it did not work. Below is what I have in my code. After looking through the Word Object Browser and using Help, I don't...

Is there code to export to standard fixed length text file?
I can do this manually but it's more than a couple clicks. I'd like to automate this from the MDB that I can call from my C# process call or an OLE call. Thanks much! AFAIK the choices are: 1) write code in your C# application that opens a recordset, assembles the fixed-length records and writes them to a text file. 2) use the Jet Text ISAM to write the file, either by automating Access or by writing to the DAO library. Either way you'll need to provide a schema for the text file. The options are an Access import/export specification stored in the mdb file, or a schema.ini f...

Event ID 3009 A non-delivery report with a status code of 5.1.0 appears randomly.
Exchange 2003 mail enabled Public Folder randomly don't receive e-mail from external sender, when it happens sender receives error : --------------------------------------------- Final-Recipient: rfc822;xxx@xxx.com Action: failed Status: 5.1.0 --------------------------------------------- Sometimes all work ok. Error in Application log : --------------------------------------------- Event Type: Error Event Source: MSExchangeTransport Event Category: (8) Event ID: 3009 Date: 2005.12.21 Time: 11:43:32 User: N/A Computer: MailServerName Description: The description for Event ID ( 3009 ...

Convert expression to code
Hi All, I have a conditional formatting expression i would like to convert to code, and need some help! I want the code to be in the OnOpen event of a report (called rptAllInformation). If the value of [DIA FORM ISSUED] is more than 6 weeks ago, and [DIA RESPONSE RECEIVED] is null, then label (lblOverdueWarning) becomes visible At the moment the expresson is: [DIA RESPONSE RECEIVED] Is Null And [DIA FORM ISSUED]<DateAdd("w",-6,Date()) Can anyone help? Kirstie "Kirstie Adam" <kirstiea@ecosse.net(nospam)> wrote: >Hi All, > >I have a conditiona...

XML Serialisation & Circular References
I have been able to get simple circular references to be serialized in xml by using the ImportTypeMapping method on the SoapReflectionImporter class. But I am unable to serialise circular references when the circular reference is contained with in a collection class, specifically I am using a custom ArrayList object. I keep getting a StackOverFlow Exception from the XmlSerializer class when attempting the serialisation. The classes are: Class A, Class B - this is derived from System.Collection.ArrayList Class C. Class A contains an instance of B Class B contains multiple instances of C Cl...

Coding error
I have a code (see below) that keeps receiving a run-time error (2166) that states "you can't lock a control while it has unsaved changes"...I have in my code a command that should save the record before it actually locks the field but for some reason does not seem to work. Can anyone see what might be wrong with my code that would be causing this to happen? Here is my code: Private Sub NoResponse_Checkbox_Click() If Me!NoResponse_Checkbox = True Then Me!Update_Letter_Comments.Locked = False DoCmd.GoToControl "Update_Letter_comments" ...

code error
Please can anyone help - my PC runs out of memory (I currently have 512) I'm presuming that my code is badly written - can anyone please help with this, code follows: Private Sub CommandButton1_Click() ' Option box allowing user to select relevant ctr filetoopen = Application _ .GetOpenFilename("Excel Files (*.xls), *.xls") If filetoopen <> False Then Workbooks.Open Filename:= _ filetoopen End If Dim strPath As String, strFileName As String strPath = ActiveWorkbook.FullName strFileName = Mid(strPath, InS...

Using Rational Purify on MFC Code
Does anyone have experience using Purify on C++/MFC code. I am getting a lot of MPKs and MLKs that appear to be in Microsoft code. For example the following output from Purify is for a memory leak from MQOpenQueue(). [W] MLK: Memory leak of 36 bytes from 1 block allocated in CMSMQQueue::Open(CString) Distribution of leaked blocks Allocation location LocalAlloc [KERNEL32.dll] CMSMQQueue::Open(CString) [MSMQQueue.cpp:51] WCHAR wszQueueName[ 256 ] = {0}; mbstowcs( wszQueueName, sQueueName, sQueueName.GetLength() ); => hRes = MQOpenQueue( wszQu...

XSLT, XMl
I have small problem with XslTransformation. I get from WebService xml document. I have xslt and I want transform xml document to html code. It's look easy but I cant't manage with xPath. Maybe someone help me with that. I have problems with xPath in xslt file. I can't navigate by names only by vertical and horizontal axis. What's wrong .... --- Code --- // WebService XmlForAnalysis.Xmla xa = new XmlForAnalysis.Xmla(); xa.Url = urlXmla; XmlForAnalysis.Properties properties = new XmlForAnalysis.Properties(); properties.Content = XmlForAnalysis.Content.Data; // Result Xml...

Outlook 2003: Rules based on the HTML code
Is there a method, either directly or with the macro language to make rules based on the actual HTML code rather than on the rendered HTML message body. I want to right something that catches some SPAM messages that are random text and images. AFAIK, no, there isn't. --=20 Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. After furious head scratching, Dave asked: | Is there a method, either directly or with the macro language to make | rules based on the actual HTML code rather than on the rendered HTML | message body.=20 |=20 | I want t...

"save" button not requerying as coded
Using Access 2007 I have a form (frmNewFamily) that is opened when a NotInList event is triggered from a subform in a different form (frmAttendance/sfrAttendee). I have a "Save" button on the frmNewFamily that will save the record, close the frmNewFamily and requery the combo boxes on sfrAttendee. I have it working just great, but I want to delete one of the combo boxes. But as soon as I comment out the requery line, the Save button stops functioning properly. It will save the record to the table, but not close the form or requery the combo box. The same thing...

help with Disabled code please
Hello All ! Was just wondering if someone can help me with a little code. I know bits of what I want to do but getting a bit confused... Basically I have two forms, on one form is a button that opens up the second form using... On_Click DoCmd.OpenForm "Jobs", , , , acFormAdd what I would also like it to do is from that button only that when the second form opens certain buttons and combos are disabled. I want this to only happen from the button and not if the 2nd form is opened on its own without the 1st form. Im guessing that I need to add additional code to the on click part ...

Updating Excel spreadsheet with code.
I have a client who needs a small spreadheet to be e- mailed to his PDA on request. I have compiled a VBS script which does this without a hitch, however, the spreadsheet updates itself from Bloomberg and other resources on the network. Is there anyway to run a scheduled task or VCB code which will open this file unattended thus updating the data. The file is password protected. ...

Merging XML Documents (with ADO.NET?)
I have got 2 XML documents, both of which conform to the same XSD Schema, which define possible optional elements. The 2 XML documents contain 2 disjoint set of XML elements. What is the best, easiest, most efficient way of merging the 2 XML Documents? Can I use DataSet.Merge() facility in ADO.NET?? Any pre-requisites? Any other suggestions? Patrick, Can you provide an example of each XML document? Its not clear to me how the schema can be the same if each XML document has different sets of XML elements. Also, you didn't indicate what you wanted to do after merging the XML ...

Xml Serialization problem...
Hi, I am trying to use xml serialization to simplify load/save functions in some classes i have created and am hitting a few problems. Any help to either would be most appreciated. I have created a MasterShape class which contains a name, and a 'Shapes' class object, which itself uses the ICollection interface to provide a class which is basically an array of shapes i derive from an abstract base class AbShape, for example i derive Rectangle and Circle from AbShape and wish to be able to store any combination of these shapes.. The problems.. 1) As far as i know classes which imple...

Export to XML question
Hi All, The below is a test code to export xml file. The fields Comment and Tip hold xHTML code. The problem occurs if I add the Tip field then I get the following error: The XML page cannot be displayed Required white space was missing. Error processing resource 'file:///C:/1.xml'. Line 1, Position 646 It seems that XM file cannot fully exported and some text is missing. I apprecaite any input. DECLARE @SQL VARCHAR(1024) DECLARE @sqlFlds1 VARCHAR(225) DECLARE @sqlFlds2 VARCHAR(225) DECLARE @sqlFlds3 VARCHAR(225) DECLARE @sqlFlds4 VARCHAR(225) DECLARE @sqlSt...

Will deleting a Form delete attached code? AND How to see ALL code in dB ?
1 Will deleting a Form delete any code attached to the form? 2 Is there a way to see all the code associated with an Access data base? 3 - Or must you open every form and ask for code view? Or what? 3 - Can you print all the code out at once or must you open each object and print code associated with that object? thanks for the help. Mel "Mel" <MyEmailList@gmail.com> wrote in message news:1177956107.236707.142280@h2g2000hsg.googlegroups.com... >1 Will deleting a Form delete any code attached to the form? Well, the answer is "kind of" yes. It is important t...

Changing Properties of Fields in Table
Below is part of a code that somebody had given me to change the property of a field (in this case to make the field a required field). fld1.properties("Required") = True What do I need to do if I want to modify this line of code to do the following: a) Change a field to have a DATATYPE of Number b) FIELD SIZE should be DOUBLE Any help will be appreciated. Toks You cannot change data types in that way. Your choices are: 1) Create a new field of the correct type, run an Update query to transfer the data from the old field to the new field, delete the old field then rename ...

What, Why three areas to save code
Hi My questions relate to the "Why", "Where" and "What" type of macro code should be stored in (I believe 3 places) that Excel has. 1. in the worksheet. 2. in a module/s. 3. in the Personal.xls. I understand the reasons for the No.3. Personal.xls is opened but hidden at Excel Start-up. This allows the user to add a command button to a toolbar to carry out a specific task on any workbook opened and call up any procedure within Personal.xls. Could someone explain the "Why", "Where" and "What" of the other two places; What was e...

Question understanding a line of code
hi - I'm working through examples of code, learning what I can. In Allen Browne's web site, there is a 'Function ShowFieldsRS(strTable)'. I'm trying to understand the purpose of the 'False' in the code fragment below. strSql = "SELECT " & strTable & ".* FROM " & strTable & " WHERE (False);" The code works perfectly, but I don't understand why. I would have thought that 'WHERE(False)' would allow no records to be chosen. just wonderin' Victoria "Victoria" <Victoria...

VBA-code for search,copy and paste
My sheet 1 col A values are unique values.Match sheet names from(sheet2) from these col A values of sheet1 copy that row values(from row2) and paste into the sheet 2 last row ...

lock code in excel EX(hyperlinks)
I HAVE MADE A SMALL PROGRAM AN NEED TO LOCK ALL CODED LINKS AND BE ABLE TO CLEAR PAGE THANKS FROM IAN ...

Embedded Function for a range of answers
I apologize because I know that someone has probably asked this before but I have tried Ecel help and have searched the forum to no avail. I want to create a formula that will give me a specific answer base upon the results of a calculation in another cell. For instance, an this isn't what I want to do, but it is the easiest way to explain it Say that a cell would have a percentage in it, I want the formula fo the next cell to result in a letter grade based upon the percentage i the aformentioned cell. So, say there is an 89% in cell A1, A2 shoul return a "B", but if there is ...

Most efficient method of searching large xml document
I am looking for the most efficient way of searching a large xml document (> 14mg). If I could get some pointers in the right direction. I am using VB.NET. It is readonly. Jim Kitterman wrote: > I am looking for the most efficient way of searching a large xml > document (> 14mg). If I could get some pointers in the right > direction. I am using VB.NET. It is readonly. If you don't need sophisticated querying such as XPath, just take XmlTextReader. -- Oleg Tkachenko [XML MVP, XmlInsider] http://blog.tkachenko.com XmlReader approach is the most performant and resour...