我想創建一個XML文件以符合某人的XSD這個XSD允許其描述標籤中的XHTML內容。我已剪短方法層次,但基本上它執行以下操作:如「Course_Overview」,「Entry_Requirements」包含XHTML不URL編碼,但是當加入的XDocument它似乎自動對其進行編碼,所以我停止XDocument網址編碼字符串
using System.Xml.Linq;
public static XDocument Create()
{
XDocument doc = new XDocument(
new XDeclaration("1.0", Encoding.UTF8.HeaderName, String.Empty),
GetCourses()
);
//ValidatingProcess(@".\xcri_cap_1_1.xsd", doc.ToString());
return doc;
}
private static XElement GetCourses(XElement provider)
{
//datatbale dt generated here from sql
for (int i = 0; i < dt.Rows.Count; i++)
{
provider.Add(new XElement("course",
new XElement("identifier", dt.Rows[i]["QN_ID"]),
new XElement("title", dt.Rows[i]["LSC Descriptor"]),
new XElement("subject", dt.Rows[i]["category"]),
new XElement("description", dt.Rows[i]["Course_Overview"],
new XAttribute("Type", "Course Overview")),
//new XElement("description", dt.Rows[i]["Entry_Requirements"]),
//new XAttribute("Type", "Entry Requirements"),
new XElement("description", dt.Rows[i]["Course_Contents"],
new XAttribute("Type", "Course Contents")),
new XElement("description", dt.Rows[i]["Assessment"],
new XAttribute("Type", "Assessment")),
new XElement("description", dt.Rows[i]["Progression_Route"],
new XAttribute("Type", "Progression Route")),
new XElement("url", "http://www.nnc.ac.uk/CourseLeaflets/Leaflet2.aspx?qnid=" + dt.Rows[i]["QN_ID"]),
GetQualification(dt.Rows[i])//,
//GetPresentation(row)
));
}
return provider;
}
字段最終與<P>
而不是<P>
。無論如何阻止這個或我將不得不使用的東西,而不是XDocument。
我從XDocument開始的原因是代碼的佈局可能會出現類似於最終結果。
謝謝我認爲這是推理,但不知道周圍的方式。雖然我剛剛發現一些鋰標籤缺少他們的結束標籤,所以我必須通過一些東西來確認它是xhtml。 – PeteT 2010-03-04 14:30:31