XmlDtdType Class
Represents a DTD type in an XML document.
Inheritance:
object
> XmlDtdType
Constructors
-
XmlDtdType()Initializes a new instance of the
XmlDtdType
class.
Properties
-
string Name { get; }Gets the name of the DTD type.
-
XmlSchemaContentType ContentType { get; }Gets the content type of the DTD type.
-
IEnumerable<XmlSchemaAttribute> Attributes { get; }Gets a collection of attributes defined for this DTD type.
Methods
-
bool IsValid(string value)Validates the specified string value against the DTD type's schema.value: string The string value to validate.
-
bool IsValid(XmlNode node)Validates the specified
XmlNode
against the DTD type's schema.node: XmlNode TheXmlNode
to validate.
Remarks
The XmlDtdType
class is used to represent the structure and constraints of elements and attributes defined within an XML DTD (Document Type Definition). It allows for validation of XML documents against these definitions.
This class is part of the System.Xml
namespace, providing core XML processing capabilities for the .NET Framework.
Example Usage
using System;
using System.Xml;
public class DtdExample
{
public static void Main(string[] args)
{
// Assuming 'dtdType' is an instance of XmlDtdType obtained from parsing a DTD
// For demonstration, let's imagine we have a DTD type for an element named 'book'
// In a real scenario, you would typically load this from an external DTD file or an XmlSchema object.
// Mocking an XmlDtdType for demonstration (actual instantiation is complex)
// XmlDtdType bookDtdType = ...; // Load or create XmlDtdType for 'book'
Console.WriteLine("Example usage of XmlDtdType is conceptual here.");
Console.WriteLine("In practice, you would use XmlSchema objects to represent DTDs.");
// Example conceptual validation (not runnable without a full XmlDtdType object)
/*
string validBookTitle = "The Lord of the Rings";
string invalidBookTitle = "A Book With & Invalid Chars";
if (bookDtdType != null)
{
if (bookDtdType.IsValid(validBookTitle))
{
Console.WriteLine($"'{validBookTitle}' is a valid book title.");
}
else
{
Console.WriteLine($"'{validBookTitle}' is NOT a valid book title.");
}
if (bookDtdType.IsValid(invalidBookTitle))
{
Console.WriteLine($"'{invalidBookTitle}' is a valid book title.");
}
else
{
Console.WriteLine($"'{invalidBookTitle}' is NOT a valid book title.");
}
}
*/
}
}