Help With Program Created XML Schema

T

Terrance

Good Morning. I'm trying to create a xml file and schema file for my boss to
upload the information into Sharepoint. Everytime when he uploads the xml
file it notices there's no schema and I'm automatically generating the file;
so I decided to programmatically create a schema file. It's a simple file
and it's works accept for the last elements . Instead of writing
</xsd:element> and </xsd:schema> it places the namespace in the schema tag
and name attribute in the element closing tag. I've tried
xmlTextWriter.WriteRaw and .WriteString but it doesn't indent correctly. How
can I get these tags to be generated as I described earlier? Below is the
code (xsdWriter is XmlTextWriter object):

xsdWriter.Formatting = Formatting.Indented;
xsdWriter.Indentation = 4;
xsdWriter.WriteStartDocument();
string xsdNS = "xmlns:xsd=" +
@"""http://www.w3.org/2001/XMLSchema""";
xsdWriter.WriteStartElement("xsd:schema " + xsdNS);
xsdWriter.WriteStartElement("xsd:element name=" +
@"""main""");
xsdWriter.WriteStartElement("xsd:complexType");
xsdWriter.WriteStartElement("xsd:sequence");

for (int field = 0; field <= tablesnames.Length - 1; field++)
{
xsdWriter.WriteStartElement("xsd:element name=" + @""""
+ tablesnames[field] + @"""" +
" type=" + @"""xsd:string""");
xsdWriter.WriteEndElement();
}

xsdWriter.WriteEndElement(); //sequence
xsdWriter.WriteEndElement(); //complextype
xsdWriter.WriteEndElement();
xsdWriter.WriteEndElement();

I'm trying to generate:
<schema xsd:....>
<element name="main">
<complexType>
<sequence>
<xsd:sequence.... />
</sequence>
</complexType>
</xsd:element> -- Problem node </xsd:element name="main">
</xsd:schema> --Problem node </xsd:schema .........>
 
M

Mr. Arnold

Terrance said:
Good Morning. I'm trying to create a xml file and schema file for my boss
to
upload the information into Sharepoint. Everytime when he uploads the xml
file it notices there's no schema and I'm automatically generating the
file;
so I decided to programmatically create a schema file. It's a simple file
and it's works accept for the last elements . Instead of writing
</xsd:element> and </xsd:schema> it places the namespace in the schema tag
and name attribute in the element closing tag. I've tried
xmlTextWriter.WriteRaw and .WriteString but it doesn't indent correctly.
How
can I get these tags to be generated as I described earlier? Below is the
code (xsdWriter is XmlTextWriter object):

I think what you're looking for is the WriteAttributeString statement. You
can use Google and look it up. But as I recalled, that is how you control
name spaces on closing tags.

writer.WriteStartElement("track");
writer.WriteAttributeString("name", "Street Spirit");
writer.WriteEndElement();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top