tags:

views:

53

answers:

1

I need to generate an xml infoset but the infoset needs to contain a reference to a client's DTD. The desired out needs to contain this DTD reference

<!DOCTYPE AutoApplication SYSTEM "http://www.clientsite.com/public/DTD/autoappV1-3-level2.dtd"&gt;

This reference sits directly benath the xml declaration. Neither XProcessingInstruction or XDeclaration do the job, is there another type I need to use?

A: 

you need to add your dtd using a XDocumentType object. see here for more info. It should be noted that xlinq has pretty limited processing for DTD's, though (see msdn).

some sample code....

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Linq;
public class MainClass 
{
   public static void Main() 
   {
      XDocument xDocument = new XDocument();
      XDocumentType documentType = new XDocumentType("Books", null, "Books.dtd", null);
      xDocument.Add(documentType, new XElement("Books"));
      Console.WriteLine(xDocument);
   }
}
Muad'Dib