nareshp
October 10th, 2005, 04:45 PM
Hello Evrybody,
I am stuck at this issue for some time and I need some help about how I can validate the XML against a DTD which I generated. Here is the code which generates the XML.
String a_type=”MyRootElement”;
XmlDocument xmlDocument = new XmlDocument();
memoryStream.Position = 0;
// The memoryStream in this case is obtained by serializing an object.
xmlDocument.Load(memoryStream);
// I am removing the attributes which I don’t require.
xmlDocument.GetElementsByTagName(a_type).Item(0).Attributes.RemoveAt(1);
xmlDocument.GetElementsByTagName(a_type).Item(0).Attributes.RemoveAt(0);
// I am inserting an XmlDocumentType element into the xml
XmlDocumentType documentType = xmlDocument.CreateDocumentType(a_type, null, “file://C:/” + a_type.ToLower() + ".dtd", null);
xmlDocument.InsertAfter(documentType, xmlDocument.FirstChild);
// saving the XmlDocument back into the memoryStream.
xmlDocument.Save(memoryStream);
I am not sure how I can validate this XML against a DTD (the DTD is a separate file and it can be at any location; eg: “c:\myFile.dtd”).
Also, I don’t want the DTDs to be manually uploaded to a particular location(eg: “c:\myFile.dtd” in the above case) at the time of deployment. One solution would be to add them (DTDs) as resource files and generate sattellite assemblies, which can be easily deployed along with other dlls. I would like to know how the DTDs can be used as Resources files.
Any input on this would be very much helpful to me. I tried couple of things, which did not work for me. So, Please be a bit precise on your response.
Any new ideas and suggestions on this are highly appreciated..
Thanks a lot in advance guys,
Nareshp
I am stuck at this issue for some time and I need some help about how I can validate the XML against a DTD which I generated. Here is the code which generates the XML.
String a_type=”MyRootElement”;
XmlDocument xmlDocument = new XmlDocument();
memoryStream.Position = 0;
// The memoryStream in this case is obtained by serializing an object.
xmlDocument.Load(memoryStream);
// I am removing the attributes which I don’t require.
xmlDocument.GetElementsByTagName(a_type).Item(0).Attributes.RemoveAt(1);
xmlDocument.GetElementsByTagName(a_type).Item(0).Attributes.RemoveAt(0);
// I am inserting an XmlDocumentType element into the xml
XmlDocumentType documentType = xmlDocument.CreateDocumentType(a_type, null, “file://C:/” + a_type.ToLower() + ".dtd", null);
xmlDocument.InsertAfter(documentType, xmlDocument.FirstChild);
// saving the XmlDocument back into the memoryStream.
xmlDocument.Save(memoryStream);
I am not sure how I can validate this XML against a DTD (the DTD is a separate file and it can be at any location; eg: “c:\myFile.dtd”).
Also, I don’t want the DTDs to be manually uploaded to a particular location(eg: “c:\myFile.dtd” in the above case) at the time of deployment. One solution would be to add them (DTDs) as resource files and generate sattellite assemblies, which can be easily deployed along with other dlls. I would like to know how the DTDs can be used as Resources files.
Any input on this would be very much helpful to me. I tried couple of things, which did not work for me. So, Please be a bit precise on your response.
Any new ideas and suggestions on this are highly appreciated..
Thanks a lot in advance guys,
Nareshp