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. Web Development
  3. ASP.NET
  4. Problem with Xml and Xsd

Problem with Xml and Xsd

Scheduled Pinned Locked Moved ASP.NET
helpxmltutorialquestion
5 Posts 3 Posters 5 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.
  • A Offline
    A Offline
    AndyASPVB
    wrote on last edited by
    #1

    Hi I have minor problem which I need help with. I need to write a method that takes my xsd and my xml file, when I compare my xsd with my xml, if there are any elements in the xml data missing to add them into the xml file as empty. Firstly, let me say, I am not validating the xml file, this is not the purpose. All I am doing is comparing the two files, and adding back in any elements that are missing. The result of the new xml file is then displayed to the user. Can anyone give me some pointers on how to do this, please?

    B E 2 Replies Last reply
    0
    • A AndyASPVB

      Hi I have minor problem which I need help with. I need to write a method that takes my xsd and my xml file, when I compare my xsd with my xml, if there are any elements in the xml data missing to add them into the xml file as empty. Firstly, let me say, I am not validating the xml file, this is not the purpose. All I am doing is comparing the two files, and adding back in any elements that are missing. The result of the new xml file is then displayed to the user. Can anyone give me some pointers on how to do this, please?

      B Offline
      B Offline
      brunoseixas
      wrote on last edited by
      #2

      I don't have sure, but if you wanna search something about "ReadXmlSchema" method.. maybe this can help you :|

      1 Reply Last reply
      0
      • A AndyASPVB

        Hi I have minor problem which I need help with. I need to write a method that takes my xsd and my xml file, when I compare my xsd with my xml, if there are any elements in the xml data missing to add them into the xml file as empty. Firstly, let me say, I am not validating the xml file, this is not the purpose. All I am doing is comparing the two files, and adding back in any elements that are missing. The result of the new xml file is then displayed to the user. Can anyone give me some pointers on how to do this, please?

        E Offline
        E Offline
        Ennis Ray Lynch Jr
        wrote on last edited by
        #3

        Sure, use the xsd.exe tool to create a .net class file from your xml schema file. Serialize your xml file to your .NET object. Reflect over the object changing all of the fields that are in the default or null value to a non-default value. Serialize to the file system. The other option is to change your xsd file to require given elements using the minimumOccurs="1" thus a valid xml will always have a "default" value. With this method you will not have to reflect after serialization to the object.

        Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

        A 1 Reply Last reply
        0
        • E Ennis Ray Lynch Jr

          Sure, use the xsd.exe tool to create a .net class file from your xml schema file. Serialize your xml file to your .NET object. Reflect over the object changing all of the fields that are in the default or null value to a non-default value. Serialize to the file system. The other option is to change your xsd file to require given elements using the minimumOccurs="1" thus a valid xml will always have a "default" value. With this method you will not have to reflect after serialization to the object.

          Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

          A Offline
          A Offline
          AndyASPVB
          wrote on last edited by
          #4

          Hi I don't want to give the xsd a min occurance of 1 because this would defeat the business rules from where the data is actually coming from. So, I need to compare.

          E 1 Reply Last reply
          0
          • A AndyASPVB

            Hi I don't want to give the xsd a min occurance of 1 because this would defeat the business rules from where the data is actually coming from. So, I need to compare.

            E Offline
            E Offline
            Ennis Ray Lynch Jr
            wrote on last edited by
            #5

            Actually it won't. <shipDate xsi:nil="true"></shipDate> This example is from the spec:http://www.w3.org/TR/xmlschema-0/[^]

            Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

            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