Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Does this qualify as horror?

Does this qualify as horror?

Scheduled Pinned Locked Moved The Weird and The Wonderful
htmlxmlquestion
11 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Megidolaon
    wrote on last edited by
    #1

    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).

    P P S S 4 Replies Last reply
    0
    • M Megidolaon

      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).

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      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.

      M 1 Reply Last reply
      0
      • M Megidolaon

        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).

        P Offline
        P Offline
        Paul Conrad
        wrote on last edited by
        #3

        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

        S S 2 Replies Last reply
        0
        • P Paul Conrad

          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

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #4

          Agreed.

          Steve

          1 Reply Last reply
          0
          • P Paul Conrad

            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

            S Offline
            S Offline
            StM0n
            wrote on last edited by
            #5

            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.AppendChild = xmlDocument.CreateElement("evil");

            ;o)

            (yes|no|maybe)*

            P 1 Reply Last reply
            0
            • S StM0n

              XmlDocument xmlDocument = new XmlDocument();
              xmlDocument.AppendChild = xmlDocument.CreateElement("evil");

              ;o)

              (yes|no|maybe)*

              P Offline
              P Offline
              Paul Conrad
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • P PIEBALDconsult

                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.

                M Offline
                M Offline
                Megidolaon
                wrote on last edited by
                #7

                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.

                P 2 Replies Last reply
                0
                • M Megidolaon

                  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).

                  S Offline
                  S Offline
                  Spacix One
                  wrote on last edited by
                  #8

                  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|


                  1 Reply Last reply
                  0
                  • M Megidolaon

                    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).

                    S Offline
                    S Offline
                    supercat9
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • M Megidolaon

                      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.

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • M Megidolaon

                        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.

                        P Offline
                        P Offline
                        PIEBALDconsult
                        wrote on last edited by
                        #11

                        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.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups