怎样根据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);
}
相关问答:
txt 和XML 格式相应
不借助DataSet
导入读取TXT文件
然后直接写入XML(同一文件,不同数据,递增原数据没有被覆盖情况下增加数据.)
教个要点或最好是有个代码提示的
过路好汉 帮个忙撒^^
不会,帮楼主 ......
<?xml version="1.0" encoding="utf-8" ?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical&q ......
我有一个类似的xml的 string,想通过遍历怎么个xml 输出我想要的element的值
xml 为:
<Discover xmlns="urn:schemas-microsoft-com:xml-analysis">
<RequestType>DISCOVER_XML_ME ......
现在我写了存储过程,把表里面的数据导出到xml中,现在的格式是:
<?xml version="1.0" encoding="GBK" ?>
<PEOPLE>
<PERSON PERSONID="1">
&l ......
我要在网页上上传一个XML文件,我在C#中写了一个验证XML文件格式的方法:
private bool ValidateXml(string xmlFilePath)
{
string xsdPath = Request.PhysicalApp ......