Problem with Xml and Xsd
-
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?
-
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?
I don't have sure, but if you wanna search something about "ReadXmlSchema" method.. maybe this can help you :|
-
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?
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
-
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
-
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.
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