Does this qualify as horror?
-
Been refactoring some of my code and stumbled upon this.
string XMLCommand = "<<Command Name=\"DoStuff\" ID=\"";
XMLCommand += ID.ToString();
XMLCommand += "\"/>";The double << are necessary or the site wouldn't display all code (why actually? It shouldn't be any valid HTML tag). I know, I should use the proper XML classes but I've been too lazy, especially cause 3 lines below it, I'd need to convert it to a string anyway (to send it with a StreamWriter).
-
Been refactoring some of my code and stumbled upon this.
string XMLCommand = "<<Command Name=\"DoStuff\" ID=\"";
XMLCommand += ID.ToString();
XMLCommand += "\"/>";The double << are necessary or the site wouldn't display all code (why actually? It shouldn't be any valid HTML tag). I know, I should use the proper XML classes but I've been too lazy, especially cause 3 lines below it, I'd need to convert it to a string anyway (to send it with a StreamWriter).
Yes, for a number of reasons including the concatenation of strings. I suggest you use something more like
string XMLCommand = string.Format
(
"<<Command Name=\"DoStuff\" ID=\"{0}\"/>"
,
ID
) ;But that still doesn't explain the extra less-than; you should find out what the problem is.
-
Been refactoring some of my code and stumbled upon this.
string XMLCommand = "<<Command Name=\"DoStuff\" ID=\"";
XMLCommand += ID.ToString();
XMLCommand += "\"/>";The double << are necessary or the site wouldn't display all code (why actually? It shouldn't be any valid HTML tag). I know, I should use the proper XML classes but I've been too lazy, especially cause 3 lines below it, I'd need to convert it to a string anyway (to send it with a StreamWriter).
Anything to do with XML is a coding horror :rolleyes:
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
Anything to do with XML is a coding horror :rolleyes:
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
Agreed.
Steve
-
Anything to do with XML is a coding horror :rolleyes:
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.AppendChild = xmlDocument.CreateElement("evil");;o)
(yes|no|maybe)*
That's evil :laugh: Seriously, that is okay, I've seen worse :rolleyes:
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
Yes, for a number of reasons including the concatenation of strings. I suggest you use something more like
string XMLCommand = string.Format
(
"<<Command Name=\"DoStuff\" ID=\"{0}\"/>"
,
ID
) ;But that still doesn't explain the extra less-than; you should find out what the problem is.
PIEBALDconsult wrote:
string XMLCommand = string.Format
What is string.Format?
PIEBALDconsult wrote:
But that still doesn't explain the extra less-than; you should find out what the problem is.
I explained in in my first post already, it's because CodeProject only displays half the code without it.
s_mon wrote:
XmlDocument xmlDocument = new XmlDocument(); xmlDocument.AppendChild = xmlDocument.CreateElement("evil");
I know, I know. I wrote the code before knowing any XML classes and just been too lazy to change it now. Also, I don't think it's necessary to create a new XMLDoc and append an element and Attribute just so I'll pass the OuterXml to the send method anyway. It's quick & dirty but it does it's job and for a single line of XML I think it's ok. I use the proper classes when building larger XML.
-
Been refactoring some of my code and stumbled upon this.
string XMLCommand = "<<Command Name=\"DoStuff\" ID=\"";
XMLCommand += ID.ToString();
XMLCommand += "\"/>";The double << are necessary or the site wouldn't display all code (why actually? It shouldn't be any valid HTML tag). I know, I should use the proper XML classes but I've been too lazy, especially cause 3 lines below it, I'd need to convert it to a string anyway (to send it with a StreamWriter).
Megidolaon wrote:
string XMLCommand = "<<Command Name=\"DoStuff\" ID=\"";
XMLCommand += ID.ToString();
XMLCommand += "\"/>";My eyes! The goggles do nothing!
-Spacix All your skynet questions[^] belong to solved
I dislike the black-and-white voting system on questions/answers. X|
-
Been refactoring some of my code and stumbled upon this.
string XMLCommand = "<<Command Name=\"DoStuff\" ID=\"";
XMLCommand += ID.ToString();
XMLCommand += "\"/>";The double << are necessary or the site wouldn't display all code (why actually? It shouldn't be any valid HTML tag). I know, I should use the proper XML classes but I've been too lazy, especially cause 3 lines below it, I'd need to convert it to a string anyway (to send it with a StreamWriter).
Why should it qualify as a horror? Admittedly, the use of strings in that fashion is not terribly efficient, but since they're small and the number of operations is comparatively modest I wouldn't consider the inefficiency particularly objectionable if the code isn't executed too often (if 90% of the time is spent in 10% of the code, it wouldn't matter much if the other 90% of the code were twice as slow as it should be). My own preference, especially if more parts were being assembled into the string, would be to either use something like a StringBuilder so as to avoid repeated allocations for the different partially-assembled strings, but I don't see anything particularly wrong with the code as given, or else (if using C++ or C#, as opposed to VB) spread one statement over multiple lines. The strings in the above example are short enough that using a simple string type is probably fine, though, and spreading statements over multiple lines isn't particularly aesthetically pleasing.
-
PIEBALDconsult wrote:
string XMLCommand = string.Format
What is string.Format?
PIEBALDconsult wrote:
But that still doesn't explain the extra less-than; you should find out what the problem is.
I explained in in my first post already, it's because CodeProject only displays half the code without it.
s_mon wrote:
XmlDocument xmlDocument = new XmlDocument(); xmlDocument.AppendChild = xmlDocument.CreateElement("evil");
I know, I know. I wrote the code before knowing any XML classes and just been too lazy to change it now. Also, I don't think it's necessary to create a new XMLDoc and append an element and Attribute just so I'll pass the OuterXml to the send method anyway. It's quick & dirty but it does it's job and for a single line of XML I think it's ok. I use the proper classes when building larger XML.
Ohhh... so that's what you meant by "the site wouldn't display all code", I had assumed you meant some site you were working on. Try escaping the < with < (which is what the "Auto-encode HTML when pasting?" does.
-
PIEBALDconsult wrote:
string XMLCommand = string.Format
What is string.Format?
PIEBALDconsult wrote:
But that still doesn't explain the extra less-than; you should find out what the problem is.
I explained in in my first post already, it's because CodeProject only displays half the code without it.
s_mon wrote:
XmlDocument xmlDocument = new XmlDocument(); xmlDocument.AppendChild = xmlDocument.CreateElement("evil");
I know, I know. I wrote the code before knowing any XML classes and just been too lazy to change it now. Also, I don't think it's necessary to create a new XMLDoc and append an element and Attribute just so I'll pass the OuterXml to the send method anyway. It's quick & dirty but it does it's job and for a single line of XML I think it's ok. I use the proper classes when building larger XML.
Megidolaon wrote:
It's quick & dirty but it does it's job and for a single line of XML I think it's ok.
That's what I thought until I was passed some text with values that needed to be encoded. Like < and & and even a Ctrl-C :omg: I have since worked up a class to make it easier and hide the details.