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. General Programming
  3. XML / XSL
  4. Empty node when data specified in xsd

Empty node when data specified in xsd

Scheduled Pinned Locked Moved XML / XSL
csharpcomxmlquestion
10 Posts 4 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.
  • D Offline
    D Offline
    DaveyM69
    wrote on last edited by
    #1

    I am receiving xml from an external web service that I am consuming in a C# application. The xsd has this line:

    Most of the files received have this element set to a value but I have just come across one that has it empty:

    Is this valid, or should I raise it with the web service producer?

    Dave
    Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
    BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

    L J 2 Replies Last reply
    0
    • D DaveyM69

      I am receiving xml from an external web service that I am consuming in a C# application. The xsd has this line:

      Most of the files received have this element set to a value but I have just come across one that has it empty:

      Is this valid, or should I raise it with the web service producer?

      Dave
      Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      It's syntactically valid XML; what's the problem?

      Use the best guess

      D 1 Reply Last reply
      0
      • L Lost User

        It's syntactically valid XML; what's the problem?

        Use the best guess

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        I would expect that a value of 0 to 255 would be present for an element marked as byte and it should never be empty. It caused the .NET XmlSerializer to throw an exception when deserializing the data. I have done a work around by deserializing to a string instead and having an additional property that returns the result parameter of byte.TryParse on the string, but it's a bit messy.

        Dave
        Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

        L 1 Reply Last reply
        0
        • D DaveyM69

          I would expect that a value of 0 to 255 would be present for an element marked as byte and it should never be empty. It caused the .NET XmlSerializer to throw an exception when deserializing the data. I have done a work around by deserializing to a string instead and having an additional property that returns the result parameter of byte.TryParse on the string, but it's a bit messy.

          Dave
          Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          If you think it's wrong then you should talk to the provider of the XML data.

          Use the best guess

          D 1 Reply Last reply
          0
          • L Lost User

            If you think it's wrong then you should talk to the provider of the XML data.

            Use the best guess

            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #5

            I have raised it with them, but not being very knowledgeable in the finer points of XML/XSD I wasn't sure about it's validity.

            Dave
            Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

            N L 2 Replies Last reply
            0
            • D DaveyM69

              I have raised it with them, but not being very knowledgeable in the finer points of XML/XSD I wasn't sure about it's validity.

              Dave
              Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
              BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

              N Offline
              N Offline
              Nicholas Marty
              wrote on last edited by
              #6

              Try making the byte a nullable. As far as I know byte is generally a value type which means it can't be null. e.g. in c#

              byte? elementName

              D 1 Reply Last reply
              0
              • D DaveyM69

                I have raised it with them, but not being very knowledgeable in the finer points of XML/XSD I wasn't sure about it's validity.

                Dave
                Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                I have had a look round a few sites but could not find a definitive statement on this.

                Use the best guess

                D 1 Reply Last reply
                0
                • L Lost User

                  I have had a look round a few sites but could not find a definitive statement on this.

                  Use the best guess

                  D Offline
                  D Offline
                  DaveyM69
                  wrote on last edited by
                  #8

                  The dev at the company who provide the web service got back to me saying there should always be a value, and they would of course fix it.

                  Dave
                  Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                  BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                  1 Reply Last reply
                  0
                  • N Nicholas Marty

                    Try making the byte a nullable. As far as I know byte is generally a value type which means it can't be null. e.g. in c#

                    byte? elementName

                    D Offline
                    D Offline
                    DaveyM69
                    wrote on last edited by
                    #9

                    Yes, you are correct about byte being a value type (in .NET anyway). I haven't tried using nullable so don't know how the XmlSerializer will respond to it - could be interesting!

                    Dave
                    Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                    BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                    1 Reply Last reply
                    0
                    • D DaveyM69

                      I am receiving xml from an external web service that I am consuming in a C# application. The xsd has this line:

                      Most of the files received have this element set to a value but I have just come across one that has it empty:

                      Is this valid, or should I raise it with the web service producer?

                      Dave
                      Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                      J Offline
                      J Offline
                      jinzai
                      wrote on last edited by
                      #10

                      It is valid -- but, the creator of the XSD did not indicate that it was required -- and you have assumed that it is required. If your code cannot tolerate that -- then modify the XSD to make it required and have whoever produces the XML give it a default value.... However, this is simply pushing it off to the side. This is an issue that does not relate to XML per se -- it relates to best practices about defining and validating data. The XSD defines the structure and rules of XML -- so the designer of the schema must describe the data perfectly and consumers must not make assumptions that are not supported by the XSD.

                      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