Click here to Skip to main content
16,004,974 members
Home / Discussions / C#
   

C#

 
QuestionRSACryptoServiceProvider asymmetric error Pin
Suresh Ramasamy10-Sep-08 5:26
Suresh Ramasamy10-Sep-08 5:26 
AnswerRe: RSACryptoServiceProvider asymmetric error Pin
Mbah Dhaim10-Sep-08 8:38
Mbah Dhaim10-Sep-08 8:38 
QuestionStrange List<string> sorting request</string> Pin
Vodstok10-Sep-08 4:44
Vodstok10-Sep-08 4:44 
AnswerRe: Strange List sorting request Pin
Ennis Ray Lynch, Jr.10-Sep-08 5:08
Ennis Ray Lynch, Jr.10-Sep-08 5:08 
AnswerRe: Strange List sorting request Pin
Guffa10-Sep-08 5:19
Guffa10-Sep-08 5:19 
GeneralRe: Strange List sorting request Pin
Vodstok10-Sep-08 5:28
Vodstok10-Sep-08 5:28 
GeneralRe: Strange List sorting request Pin
Mbah Dhaim10-Sep-08 7:59
Mbah Dhaim10-Sep-08 7:59 
QuestionHow can I built an XmlDocument from scratch and then validate it? Pin
JNeave10-Sep-08 4:43
JNeave10-Sep-08 4:43 
Hi,

I need to build XML files and populate them with data from our database.
They need to conform to a schema defined by a third party.
Unfortunately the schema is too complex to build a stronly typed DataSet from so I'm going to have to write the XML building code myself.

I'm having difficulty so I've built a simple test application to build and validate some XML.
But I can't get it to work, XmlDocument.Validate just succeeds even if the XML is wrong.

Here is the sample code as well as the respective XML and XSD files.

Container.xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Container" targetNamespace="http://www.spursolutions.com/Container.xsd" elementFormDefault="qualified" xmlns="http://www.spursolutions.com/Container.xsd" xmlns:mstns="http://www.spursolutions.com/Container.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Envelope" nillable="false">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Header" nillable="false">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Source" type="xs:string" nillable="false" />
              <xs:element name="Dest" type="xs:string" nillable="false" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="Payload" type="xs:anyType" nillable="false" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>


Code
using System;
using System.Xml;
using System.Xml.Schema;

namespace XMLTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Validate();
        }

        public static void Validate()
        {
            XmlDocument oDoc;

            oDoc = new XmlDocument();
            oDoc.Schemas.Add("http://www.spursolutions.com/Container.xsd", "Container.xsd");

            oDoc.AppendChild(oDoc.CreateXmlDeclaration("1.0", "utf-8", null));
            oDoc.AppendChild(oDoc.CreateElement("Envelope"));
            oDoc.DocumentElement.SetAttribute("xmlns", "http://www.spursolutions.com/Container.xsd");

            ValidationEventHandler eventHandler = new ValidationEventHandler(ValidationEvent);
            oDoc.Validate(eventHandler);
        }

        public static void ValidationEvent(object sender, ValidationEventArgs e)
        {
            Console.WriteLine(e.Message);
            Console.WriteLine(e.Severity.ToString());
            if (e.Severity == XmlSeverityType.Error)
            {
                throw e.Exception;
            }
        }
    }
}


Now, if I save that XML file, then change the code to load it in instead of creating it from scratch, it fails the Validation.

Can anybody help? Having to save and load the XML to validate it is a rather ugly solution.

Thanks,

James.
AnswerRe: How can I built an XmlDocument from scratch and then validate it? Pin
Monark10-Sep-08 14:19
Monark10-Sep-08 14:19 
QuestionThraed time ! Pin
Mohammad Dayyan10-Sep-08 4:39
Mohammad Dayyan10-Sep-08 4:39 
AnswerRe: Thraed time ! Pin
JNeave10-Sep-08 4:54
JNeave10-Sep-08 4:54 
AnswerRe: Thraed time ! Pin
leppie10-Sep-08 4:56
leppie10-Sep-08 4:56 
AnswerRe: Thraed time ! Pin
Guffa10-Sep-08 5:22
Guffa10-Sep-08 5:22 
GeneralRe: Thraed time ! Pin
Mohammad Dayyan10-Sep-08 7:44
Mohammad Dayyan10-Sep-08 7:44 
AnswerRe: Thraed time ! Pin
#realJSOP10-Sep-08 7:49
professional#realJSOP10-Sep-08 7:49 
GeneralRe: Thraed time ! Pin
Mohammad Dayyan10-Sep-08 7:53
Mohammad Dayyan10-Sep-08 7:53 
QuestionProblem with String Pin
Rick van Woudenberg10-Sep-08 3:46
Rick van Woudenberg10-Sep-08 3:46 
AnswerRe: Problem with String Pin
leppie10-Sep-08 3:49
leppie10-Sep-08 3:49 
AnswerRe: Problem with String Pin
c242310-Sep-08 4:13
c242310-Sep-08 4:13 
GeneralRe: Problem with String Pin
Rick van Woudenberg10-Sep-08 4:32
Rick van Woudenberg10-Sep-08 4:32 
GeneralRe: Problem with String Pin
Ennis Ray Lynch, Jr.10-Sep-08 4:33
Ennis Ray Lynch, Jr.10-Sep-08 4:33 
GeneralRe: Problem with String Pin
c242310-Sep-08 4:42
c242310-Sep-08 4:42 
QuestionView source of a control Pin
ZeXr010-Sep-08 3:19
ZeXr010-Sep-08 3:19 
AnswerDon't use the IDE Pin
Ennis Ray Lynch, Jr.10-Sep-08 3:24
Ennis Ray Lynch, Jr.10-Sep-08 3:24 
GeneralRe: Don't use the IDE Pin
ZeXr010-Sep-08 4:29
ZeXr010-Sep-08 4:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.