Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to send a http request from client to local server and on the server I made a query with Linq that returns data in xml I also have .xsd file and a .cs file enerated from my xsd file that I want to validate my xml with. I have several questions:

how can I validate xml with c# generated class?
how can I return xml from server to client?


this is my c# class:

C#
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.34209
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System.Xml.Serialization;

// 
// This source code was auto-generated by xsd, Version=4.0.30319.17929.
// 


/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class FlashList {
    
    private FlashListFlash flashField;
    
    /// <remarks/>
    public FlashListFlash flash {
        get {
            return this.flashField;
        }
        set {
            this.flashField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class FlashListFlash {
    
    private string vinField;
    
    private string modelTypeField;
    
    public string Vin {
        get {
            return this.vinField;
        }
        set {
            this.vinField = value;
        }
    }
    public string ModelType {
        get {
            return this.modelTypeField;
        }
        set {
            this.modelTypeField = value;
        }
    }
}


and this is my XML format:

XML
<FlashList>
   <flash>
      <Vin>aa123654654s6546</Vin>
      <ModelType>x23j</ModelType>
   </flash>
</FlashList>


and this is my main file that I made the query:

C#
namespace WebApplication1
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]

    public class MyWebService : System.Web.Services.WebService
    {
       
        [WebMethod]
        public XXX MyService(string vinValue)
        {
            FlashListFlash flash = new FlashListFlash();


            LinqSqlDataContext db = new LinqSqlDataContext();
            var reportdata =    from Vin in db.Vin
                                from Global in db.Globals
                                from Associate in db.Associas
                                where Vin.Vin == vinValue && Vin.NHard == Global.NHard &&
                                Global.NomeFile == Associate.KeyJoined &&
                                SqlMethods.Like(Global.NVerHard, "0" + Vin.NVerHard)
                                select new XElement("flash",
                                    new XElement("Vin", Vin.Vin),
                                    new XElement("ModelType", Associate.Model_Type)
                                );



            XElement reportXml = new XElement("FlashList", reportdata);
            string fileName = @"D:\FlashList.xml";
            Directory.CreateDirectory(Path.GetDirectoryName(fileName));
            reportXml.Save(fileName);
            return XXX;
        }
    }
}
Posted
Updated 20-Apr-15 5:27am
v3
Comments
Maciej Los 20-Apr-15 12:01pm    
You can't validate xml file with C# class. You can validate the xml content corresponds to the data structure and data type. Search Google for XML validator.

1 solution

Wikkipedia wrote:
XML validation is the process of checking a document written in XML (eXtensible Markup Language) to confirm that it is both well-formed and also "valid" in that it follows a defined structure. A well-formed document follows the basic syntactic rules of XML, which are the same for all XML documents.[1] A valid document also respects the rules dictated by a particular DTD or XML schema, according to the application-specific choices for those particular

Source: http://en.wikipedia.org/wiki/XML_validation[^]

I'd suggest to read this:
How to: Validate Using XSD (LINQ to XML)[^]
XML Schema (XSD) Validation with XmlSchemaSet[^]
XmlSchemaValidator Class[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900