Output my XML schema to HTML



I have a schema generator that uses an XmlSchema to build an xml based on an EF model.


My problem is, I would like to return the XMLschema in a human readable format so I can display it in HTML to an the end user.


I've tried using toString(), however this doesn't work. What would be the best way to return my XMLSchema?


The xml formats correctly, I guess I just don't know how to return it to the frontend so I can wrap it in highlighting


Code Below:



public ActionResult ResourceXML(int id)
{
Resource res = db.Resources.Find(id);
res.Properties = db.ResourceProperties.Where(c => c.ResourceId == id).ToList();

XmlSchema schema = new XmlSchema();
XmlSchemaElement resource = new XmlSchemaElement();

schema.Namespaces.Add("hrr", "http://ift.tt/1Ke9H7v");
schema.Namespaces.Add("xs", "http://ift.tt/tphNwY");
schema.TargetNamespace = "http://ift.tt/rAg5Mm";

resource.Name = res.Name;
resource.SchemaTypeName = new XmlQualifiedName("string", "http://ift.tt/tphNwY");
resource.Id = ""+res.Id;

//annotation
XmlSchemaAnnotation resourceAnno = new XmlSchemaAnnotation();
resource.Annotation = resourceAnno;

//documentation
XmlSchemaDocumentation docs = new XmlSchemaDocumentation();
resourceAnno.Items.Add(docs);
docs.Markup = TextToNodeArray(""+res.Description);

//complex type
XmlSchemaComplexType complexType = new XmlSchemaComplexType();

//sequence
XmlSchemaSequence sequence = new XmlSchemaSequence();
complexType.Particle = sequence;

foreach (var property in res.Properties)
{
XmlSchemaElement element = new XmlSchemaElement();

element.Name = property.Name;
element.SchemaTypeName = new XmlQualifiedName(GetTheType(property), "http://ift.tt/tphNwY");
element.Id = property.Id+"";

if (property.Required)
{
element.MinOccurs = 1;
}
else
{
element.MinOccurs = 0;
}

if (property.List)
{
element.MaxOccursString = "unbounded";
}
else
{
element.MaxOccursString = "1";
}
//annotation
XmlSchemaAnnotation elemAnno = new XmlSchemaAnnotation();
element.Annotation = elemAnno;

//documentation
XmlSchemaDocumentation elemDoc = new XmlSchemaDocumentation();
resourceAnno.Items.Add(elemDoc);
//No property data
elemDoc.Markup = TextToNodeArray("");

sequence.Items.Add(element);
}

schema.Items.Add(resource);
schema.Version = "" + res.Version.Number;
//schema.Write(stream:);
return File(stream, "text/xml");

}

No comments:

Post a Comment