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 .........>
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 .........>