linq to xml validation against a DTD file in c# - c#

I have a xml file that has
I am using linq to xml for parsing this xml. I have searched for validation of xml in linq to xml and most of the examples I get are validation against a xsd file.
Can please anyone tell me how to use linq to xml for validation against a DTD file.
Thanks.
Much obliged

From the documentation for XDocumentType:
LINQ to XML will not validate a document against a DTD, but you can use a validating XmlReader to perform DTD validation if necessary.
So it sounds like you'll need to validate the Xml using an XmlReader before trying to read it using Linq to XML

Related

Validation of XML using XSD

I am creating small application in which i am reading data from XML.
I am using XmlSearializer to read data from xml.
But before reading i am validating the xml using xsd.
So in validating xml using xsd i am having some cases which i think can not be implemented using xsd.
Some validation is based on value of other element.
So i want to make all these validation before i read data from xml.
So is there any way how can i validate xml before reading data and cases that can not be implemented using XSD?
Thanks for support.
I think it's not possible with XSD
See the other answers:
XML Schema - child elements dependent on existence of optional attribute
Restricting XML Elements Based on Another Element via XSD

Generate XML file from CSV using XSD

I am trying to implement a C# Windows Forms application to generate XML file from a CSV based on XML's schema. I want to do this as much generic as possible since I am going to transform more than 1000 csv/schemas. Any ideas would be appreciated.
There is a pretty good article exposing appropriate approach for this case
converting csv to xml with an xsd

Read DTD or Schema and list all valid child elements or attributes for a given element

I want to develop an application something like XML editor.. providing intellisense like feature when user types an element, the application will read the DTD or schema and list the valid child elements and attributes (something like Oxygen XML Editor).
Is there an API that i can get this done?
I'm not familiar with an API that performs this task.
If you choose to implement this yourself, however, here's a couple of thoughts:
An XML schema is itself an XML file, that is structured according to the meta-schema. You can easily use one of the existing APIs to unmarshal a schema into an object structure that you can easily work with in-memory.
A DTD is not an XML structure, but any DTD can be represented as a simple schema. Therefore you should try and find a way to convert a DTD into a schema (and apply your schema solution).
HTH
You might find XSD4J useful:
XSD4J is a library to parse XML Schema
files into a structure of Java
objects, convert those back into an
XML DOM tree (and hence plain text)
again, and allow for performing
several queries on the XSD objects.
The library currently supports most
real-world features such as simple and
complex types, type restrictions and
attributes.

How to use XML and XML Schemas with C#

HI,
I want to keep the Outlook contacts in an XML file. And I want to compare, merge and resolve conflicts of this XML file with another XML file which may have same attributes ?
Also I want to know when a particular node is editied/newly added ? How we can achieve this in XML using C# 3.5 ? Should I use any XML Schemas ? How this is possible ?
Also please let me know using which one is faster - a XML file or a SQLite ?
You can use LINQ to XML, there are various books on LINQ to XML, please refer them.
for small data XML should be fast and effective way to go like configuration data, etc.
for large data SQLite is the way to go.

Validation Patterns for Custom XML Documents

I have a web application that generates a medium sized XML dataset to be consumed by a third party.
I thought it would be a good idea to provide some form of schema document for the XML that I generate so I pasted the XML into Visual Studio and got it to generate an XSD.
The annoying thing is that my XML doesn't validate to the XSD that was generated!
Is it better to roll your own XSD?
What about different schema docs like DTDs, Relax NG, or Schematron?
The key is that I would like to be able to validate my document using C#.
What are your XML validation strategies?
Whether you choose XSD and/or Schematron depends on what you are trying to validate. XSD is probably the most common validation strategy, but there are limits on what it can validate. If all you want to do is ensure that the right type of data is in each field, XSD should work for you. If you need to assert, for example, that the value of the <small> element is less than the value of the <big> element, or even more complex business rules involving multiple fields, you probably want Schematron or a hybrid approach.
You will be able to validate your XML with either an XML Schema or a DTD using C#. DTDs are older standards as compared to XML Schemas.
So, I recommend an XML Schema approach.

Categories

Resources