Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The first part of your question sounds like a schema validation would work best. If you have access to the XSD's or can create them you could use an algorithm similar to this:</p> <pre><code> public void ValidateXmlToXsd(string xsdFilePath, string xmlFilePath) { XmlSchema schema = ValidateXsd(xsdFilePath); XmlDocument xmlData = new XmlDocument(); XmlReaderSettings validationSettings = new XmlReaderSettings(); validationSettings.Schemas.Add(schema); validationSettings.Schemas.Compile(); validationSettings.ValidationFlags = XmlSchemaValidationFlags.ProcessInlineSchema; validationSettings.ValidationType = ValidationType.Schema; validationSettings.ValidationEventHandler += new ValidationEventHandler(ValidationHandler); XmlReader xmlFile = XmlReader.Create(xmlFilePath, validationSettings); xmlData.Load(xmlFile); xmlFile.Close(); } private XmlSchema ValidateXsd(string xsdFilePath) { StreamReader schemaFile = new StreamReader(xsdFilePath); XmlSchema schema = XmlSchema.Read(schemaFile, new ValidationEventHandler(ValidationHandler)); schema.Compile(new ValidationEventHandler(ValidationHandler)); schemaFile.Close(); schemaFile.Dispose(); return schema; } private void ValidationHandler(object sender, ValidationEventArgs e) { throw new XmlSchemaException(e.Message); } </code></pre> <p>If the xml fails to validate the <code>XmlSchemaException</code> is thrown.</p> <p>As for LINQ, I personally prefer to use <code>XDocument</code> whenever I can over <code>XmlDocument</code>. Your goal is somewhat subjective and without seeing exactly what you're doing I can't say go this way or go that way with any certainty that it would help you. You can use XPath with <code>XDocument</code>. I would have to say that you should use whichever suits your needs best. There's no issue with using XPath sometimes and LINQ other times. It really depends on your comfort level along with scalability and readability. What will benefit the team, so to speak.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload