冷月葬花魂 发表于 2015-1-16 22:47:01

ASP.NET教程之ASP.NET技能:依据xsd天生xml文档

那做企业软件是不是最好用J2EE?asp.net|xml|技能|天生xml如今有良多的xml工具软件都能依据xsd文件誊写出xml文档,.net没有完成此办法,如是我写了几个扫瞄、校验、和创立xml的办法
全体代码以下:

usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingSystem.Xml;
usingSystem.Xml.Schema;
usingSystem.Collections;

/**////<summary>
///ProXML的择要申明
///</summary>
publicclassProXml
{
publicProXml()
{
//
//TODO:在此处增加机关函数逻辑
//
}
/**////<summary>
///取得xsd文件路径
///</summary>
publicstaticstringGetSchemaPath
{
get{
returnHttpContext.Current.Request.PhysicalApplicationPath+"App_Datasystempublish.xsd";
}
}
/**////<summary>
///获理节点
///</summary>
///<returns></returns>
publicstaticSystem.Collections.Generic.List<XmlSchemaElement>GetDatas()
{
XmlSchemaSetxsSet=newXmlSchemaSet();
xsSet.Add("http://www.w3.org/2001/XMLSchema",GetSchemaPath);
xsSet.Compile();
XmlSchemaschema=null;
foreach(XmlSchemaxsinxsSet.Schemas())
{
schema=xs;
}
System.Collections.Generic.List<XmlSchemaElement>elements=newSystem.Collections.Generic.List<XmlSchemaElement>();
foreach(XmlSchemaObjectobjinschema.Elements.Values)
{
if(obj.GetType()==typeof(XmlSchemaElement))
{
elements.Add((XmlSchemaElement)obj);
}
}
returnelements;

}
/**////<summary>
///增加元素
///</summary>
///<paramname="sourceXsd"></param>
///<paramname="titles"></param>
///<paramname="sourceXml"></param>
///<paramname="sourceNd"></param>
///<paramname="values"></param>
publicstaticvoidAddElement(XmlSchemaObjectsourceXsd,Hashtabletitles,XmlDocumentsourceXml,XmlNodesourceNd,string[]values)
{
if(sourceXsd.GetType()==typeof(XmlSchemaChoice))
{
XmlSchemaChoicechoice=sourceXsdasXmlSchemaChoice;
decimalmin=choice.MinOccurs;
foreach(XmlSchemaObjectiteminchoice.Items)
{
if(item.GetType()==typeof(XmlSchemaElement))
{
stringname=((XmlSchemaElement)item).Name;
if(titles.ContainsKey(name))
{
XmlElementelement=sourceXml.CreateElement(name);
//element.InnerText=((Excel.Range)st.Cells]).Value2.ToString();
element.InnerText=values[(int)titles];
sourceNd.AppendChild(element);
}
}
else
{
AddElement(item,titles,sourceXml,sourceNd,values);
}
}

}
elseif(sourceXsd.GetType()==typeof(XmlSchemaElement))
{
stringname=((XmlSchemaElement)sourceXsd).Name;
if(titles.ContainsKey(name))
{
XmlElementelement=sourceXml.CreateElement(name);
element.InnerText=values[(int)titles];
sourceNd.AppendChild(element);
}
}
elseif(sourceXsd.GetType()==typeof(XmlSchemaSequence))
{
foreach(XmlSchemaObjectchildItemin((XmlSchemaSequence)sourceXsd).Items)
{
if(childItem.GetType()==typeof(XmlSchemaElement))
{
stringname=((XmlSchemaElement)childItem).Name;
if(titles.ContainsKey(name))
{
XmlElementelement=sourceXml.CreateElement(name);
element.InnerText=values[(int)titles];
sourceNd.AppendChild(element);
}
}
else
{
AddElement(childItem,titles,sourceXml,sourceNd,values);
}
}
}
else
{
return;
}
}
/**////<summary>
///取得元素
///</summary>
///<paramname="name"></param>
///<returns></returns>
publicstaticSystem.Collections.Generic.List<XmlSchemaElement>GetDataItem(stringname)
{
System.Collections.Generic.List<XmlSchemaElement>arr=newSystem.Collections.Generic.List<XmlSchemaElement>();
XmlSchemaElementelement=GetTableSchema(name);
if(element==null)
{
returnnull;
}
XmlSchemaComplexTypecomplex=element.SchemaTypeasXmlSchemaComplexType;
XmlSchemaSequencesequence=complex.ContentTypeParticleasXmlSchemaSequence;

foreach(XmlSchemaObjectobjinsequence.Items)
{
if(obj.GetType()==typeof(XmlSchemaElement))
{
XmlSchemaElementitem=(XmlSchemaElement)obj;
arr.Add(item);

}
else
{
GetItem(arr,obj);
}
}
returnarr;
}
publicstaticvoidGetItem(System.Collections.Generic.List<XmlSchemaElement>arr,XmlSchemaObjectobj)
{
if(obj.GetType()==typeof(XmlSchemaElement))
{
XmlSchemaElementitem=(XmlSchemaElement)obj;
arr.Add(item);
}
elseif(obj.GetType()==typeof(XmlSchemaChoice))
{
XmlSchemaChoicechoice=objasXmlSchemaChoice;
foreach(XmlSchemaObjectchildinchoice.Items)
{
if(child.GetType()==typeof(XmlSchemaElement))
{
XmlSchemaElementitem=childasXmlSchemaElement;
arr.Add(item);
}
else
{
GetItem(arr,child);
}
}
}
elseif(obj.GetType()==typeof(XmlSchemaSequence))
{
XmlSchemaSequencesequence=objasXmlSchemaSequence;
foreach(XmlSchemaObjectchildinsequence.Items)
{
if(child.GetType()==typeof(XmlSchemaObject))
{
XmlSchemaElementitem=childasXmlSchemaElement;
arr.Add(item);
}
else
{
GetItem(arr,child);
}
}
}
else
{
return;
}
}
/**////<summary>
///依据节点名取得节点
///</summary>
///<paramname="name"></param>
///<returns></returns>
publicstaticXmlSchemaElementGetTableSchema(stringname)
{
XmlSchemaSetxsSet=newXmlSchemaSet();
xsSet.Add("http://www.w3.org/2001/XMLSchema",GetSchemaPath);
xsSet.Compile();
XmlSchemaschema=null;
foreach(XmlSchemaxsinxsSet.Schemas())
{
schema=xs;
}
XmlQualifiedNameqf=newXmlQualifiedName(name,"http://www.w3.org/2001/XMLSchema");
if(schema.Elements.Contains(qf))
{
return(XmlSchemaElement)schema.Elements;
}
returnnull;
}
staticvoidXmlValidation(objectsendor,ValidationEventArgse)
{
switch(e.Severity)
{
caseXmlSeverityType.Error:
throwe.Exception;
caseXmlSeverityType.Warning:
throwe.Exception;

}
}
/**////<summary>
///校验dom工具
///</summary>
///<paramname="doc"></param>
///<returns></returns>
publicstaticstringCheckDataXml(XmlDocumentdoc)
{
XmlSchemaSetxsd=newXmlSchemaSet();
xsd.Add("",GetSchemaPath);
doc.Schemas=xsd;
try
{
doc.Validate(newValidationEventHandler(XmlValidation));
}
catch(Exceptionex)
{
returnex.Message;
}
returnnull;
}
}
你所列的那些其实差不多都可以称为应用服务器(servlet应该说是一种语言更合适)java是开放的,相同的工具就会有很多公司在做,加上java已经发展了很多年了,因此这些工具就很多了。他们很多都是类似的。

因胸联盟 发表于 2015-1-25 22:40:30

在asp.net虚拟主机的服务提供商中,目前首推的是CNNIC的其中一家域名注册机构---时代互联(www.now.net.cn),他们早在2001年微软刚推出Asp.net时就推出了对应的Asp.net虚拟主机了,经笔者的使用测试,他提供的Asp.net性能非常的稳定,版本也会定期的更新,目前他的

飘灵儿 发表于 2015-2-4 07:08:21

Asp.net:首先来说,Asp.net和Asp没什么关系,看着像是升级版本什么的,其实没什么联系。Asp是脚本编程,用的是ASP语言,而ASP.net用的是C#语言,完全不同的东西。

蒙在股里 发表于 2015-2-9 18:32:16

可以通过在现有ASP应用程序中逐渐添加ASP.NET功能,随时增强ASP应用程序的功能。ASP.NET是一个已编译的、基于.NET的环境,可以用任何与.NET兼容的语言(包括VisualBasic.NET、C#和JScript.NET.)创作应用程序。另外,任何ASP.NET应用程序都可以使用整个.NETFramework。开发人员可以方便地获得这些技术的优点,其中包括托管的公共语言运行库环境、类型安全、继承等等。

老尸 发表于 2015-2-27 16:02:51

Servlet的形式和前面讲的CGI差不多,它是HTML代码和后台程序分开的。它们的启动原理也差不多,都是服务器接到客户端的请求后,进行应答。不同的是,CGI对每个客户请求都打开一个进程(Process)。

莫相离 发表于 2015-3-9 09:53:12

ASP.Net摆脱了以前ASP使用脚本语言来编程的缺点,理论上可以使用任何编程语言包括C++,VB,JS等等,当然,最合适的编程语言还是MS为.NetFrmaework专门推出的C(读csharp)。

小妖女 发表于 2015-3-16 21:33:49

现在的ASP.net分为两个版本:1.1和2.0Asp.net1.1用VS2003(visualstudio2003)编程。Asp.net2.0用VS2005(visualstudio2005)编程。现在一般开发用的是VS2003。

深爱那片海 发表于 2015-3-23 03:21:03

如今主流的Web服务器软件主要由IIS或Apache组成。IIS支持ASP且只能运行在Windows平台下,Apache支持PHP,CGI,JSP且可运行于多种平台,虽然Apache是世界使用排名第一的Web服务器平台。
页: [1]
查看完整版本: ASP.NET教程之ASP.NET技能:依据xsd天生xml文档