Answer the question
In order to leave comments, you need to log in
How to work with XML file in C# application?
Good evening. I have a folder of XML files with many elements, nestings, and complex structure that need to be written into several related tables. But before recording, it is necessary to check the XML for the correctness of the structure, the conformity of the data types, the contained elements, the presence of the obligatory. elements, etc.
This task is solved by checking xml files according to the xsd schema.
But I heard there is another way to implement such a check by writing C # classes with variables corresponding to xml elements, something like:
<xml>
<name>Samir</name>
<dr>1996-09-16</dr>
<okato>82000</okato>
</xml>
using System;
using System.Xml.Serialization;
using System.Collections.Generic;
namespace Xml2CSharp
{
[XmlRoot(ElementName="xml")]
public class Xml {
[XmlElement(ElementName="name")]
public string Name { get; set; }
[XmlElement(ElementName="dr")]
public DateTime Dr { get; set; }
[XmlElement(ElementName="okato")]
public string Okato { get; set; }
}
}
Answer the question
In order to leave comments, you need to log in
Let's say you validate xml against a schema.. and then what? To decompose it into a database, you still need to parse it.
@agayevskiy, No, further xml-ku is waiting for even more in-depth checks for compliance with NSI (directories), checking for the existence of certain elements in the database, etc. And this check will be carried out at the level of stored procedures (T-SQL), to which the file will be transferred as an HP parameter.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question