Skip to main content
gamedev.net
🔒 Locked

[.net] Schema based XML editor. [SOLVED]

Started by tstrimp 0 replies 950+ views
Original Post
tstrimp
tstrimp
I'm trying get information about an XML document using the schema information. Are there any classes that would make it easy to get information like what elements and/or attributes are valid for a particular element? The only thing I have found so for is the XmlSchemaValidator where I can do incremental schema validation and use GetExpectedParticles and GetExpectedAttributes as I iterate over the xml document. This isn't very convenient since it's tied to parsing and not to the node after the parsing is complete. It would be much better if I could somehow use node.SchemaInfo but I can't seem to find any relevant information in there. Is anyone else doing something similar? How should I be trying to get the available elements/atttributes for a particular element? [Edited by - tstrimp on March 15, 2007 5:07:35 PM]
tstrimp
tstrimp
I figured it out. Here is how I did it in case anyone else wanted to know.

static void Main(){  StreamReader stream = new StreamReader("schema.xsd");  XmlSchema = schema = XmlSchema.Read(stream, null);  stream.Close();  XmlDocument = doc = new XmlDocument();  doc.Load("document.xml");    doc.Schemas.Add(schema);  XmlQualifiedName qualifiedName = new XmlQualifiedName("element-name", _schema.TargetNamespace);  XmlSchemaElement element = _schema.Elements[qualifiedName] as XmlSchemaElement;  XmlSchemaComplexType type = element.SchemaType as XmlSchemaComplexType;  foreach (XmlSchemaAttribute attr in type.Attributes)  {    // Attributes    Console.WriteLine(attr.Name);  }  XmlSchemaGroupBase content = (XmlSchemaGroupBase)type.Particle;  foreach (XmlSchemaElement item in content.Items)  {    // Elements    Console.WriteLine(item.Name);  }  Console.ReadLine();}


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.