怎样根据xsd文件生成xml?
想根据xsd生成xml文件,看了下面这篇文章还是不懂:
http://www.wzsky.net/html/Program/net/74859.html
其中的AddElement应该是生成xml的函数,但是那几个参数是怎么赋值的啊?
XmlSchemaChoice,XmlSchemaSequence,XmlSchemaElement也不知道怎么用。
我把一个xsd文件读入到xmlschemad对象中,用gettype函数,却得不出上面这3个类
下次记得直接上代码!
好吧,下面是代码:
C# code:
public static void AddElement(XmlSchemaObject sourceXsd, Hashtable titles, XmlDocument sourceXml, XmlNode sourceNd, string[] values)
{
if (sourceXsd.GetType() == typeof(XmlSchemaChoice))
{
XmlSchemaChoice choice = sourceXsd as XmlSchemaChoice;
decimal min = choice.MinOccurs;
foreach (XmlSchemaObject item in choice.Items)
{
if (item.GetType() == typeof(XmlSchemaElement))
{
string name = ((XmlSchemaElement)item).Name;
if (titles.ContainsKey(name))
{
XmlElement element = sourceXml.CreateElement(name);
// element.InnerText = ((Excel.Range)st.Cells[rowIndex, (int)titles[name]]).Value2.ToString();
element.InnerText = values[(int)titles[name]];
sourceNd.AppendChild(element);
}
相关问答:
如何对xml内容数据进行比较
例如:
<?xml version='1.0' encoding='utf-8'?>
<TestLIST>
<PID>40</PID>
<TestName>深圳市</TestName>
......
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<video>
<device deviceid="\\?\usb#vid_0c45&pid_613b#5&2d0620de& ......
现在有个xml文件是<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xm ......
用xml解析后,然后再listbox中写实出来。
注:使用系统提供的xml解析器。。。有没有这方面的例子。。哪位发我一份。
邮箱:707857176@qq.com
用SyExpat啊 sax的。
www.devdiv.net可以搜到用法,也可以搜 ......
现在我写了存储过程,把表里面的数据导出到xml中,现在的格式是:
<?xml version="1.0" encoding="GBK" ?>
<PEOPLE>
<PERSON PERSONID="1">
&l ......