怎样根据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);
}
相关问答:
我在编写一个wince5.0的程序,想实现把PDA上的一个LIST <STRING>类型的数据序列化为XML,然后在PC上的一个webservice拿到这个XML,转化为Dataset,更新PC上的数据库,我想问怎么把XML传给webservice的呢?
......
我现在需要用schema来验证一个XML文件,但是却分了几个XSD文件,其中有一个主XSD文件,用#Include包含了其他的XSD文件。我在XML文件中之引用主XSD文件,但是不成功,请问我是不是要全部引用,还是其他问题?如果全部 ......
现在我写了存储过程,把表里面的数据导出到xml中,现在的格式是:
<?xml version="1.0" encoding="GBK" ?>
<PEOPLE>
<PERSON PERSONID="1">
&l ......
被解析的文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<layer name="SMU">
<layer name="rollback"><cppcompile><compile- ......
我要在网页上上传一个XML文件,我在C#中写了一个验证XML文件格式的方法:
private bool ValidateXml(string xmlFilePath)
{
string xsdPath = Request.PhysicalApp ......