我正在使用这段代码从MSDNXML创建XSD
XmlReader reader = XmlReader.Create("contosoBooks.xml");
XmlSchemaSet schemaSet = new XmlSchemaSet();
XmlSchemaInference schema = new XmlSchemaInference();
schemaSet = schema.InferSchema(reader);
foreach (XmlSchema s in schemaSet.Schemas())
{
textbox.text = s.ToString();
}
Run Code Online (Sandbox Code Playgroud)
我想根据我的xml文件输出.xsd.当我生成.xsd文件时,我得到的唯一内容是:System.Xml.Schema.XmlSchema
当我使用Visual Studio选项生成XSD来创建Schema时,它会正确显示.但是,我有超过150个xml文档,我需要创建XSD,因此需要一个编程选项.有人可以帮忙吗?
我有从对 SharePoint 站点的 REST 调用收到的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xml:base="https://XYZ.net/_api/">
<id>95d0968b-bc93-400d-9bd4-14f8a04f7933</id>
<title />
<updated>2014-05-08T12:30:49Z</updated>
<entry m:etag=""1"">
<id>df1dbe72-22e1-45af-9290-1c6571696169</id>
<category term="SP.Data.XYZABCBudgetLinesListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" href="Web/Lists(guid'7f4df39b-61e1-4657-bb81-8211276e2e75')/Items(2)" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FirstUniqueAncestorSecurableObject" type="application/atom+xml;type=entry" title="FirstUniqueAncestorSecurableObject" href="Web/Lists(guid'7f4df39b-61e1-4657-bb81-8211276e2e75')/Items(2)/FirstUniqueAncestorSecurableObject" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/RoleAssignments" type="application/atom+xml;type=feed" title="RoleAssignments" href="Web/Lists(guid'7f4df39b-61e1-4657-bb81-8211276e2e75')/Items(2)/RoleAssignments" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/AttachmentFiles" type="application/atom+xml;type=feed" title="AttachmentFiles" href="Web/Lists(guid'7f4df39b-61e1-4657-bb81-8211276e2e75')/Items(2)/AttachmentFiles" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ContentType" type="application/atom+xml;type=entry" title="ContentType" href="Web/Lists(guid'7f4df39b-61e1-4657-bb81-8211276e2e75')/Items(2)/ContentType" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesAsHtml" type="application/atom+xml;type=entry" title="FieldValuesAsHtml" href="Web/Lists(guid'7f4df39b-61e1-4657-bb81-8211276e2e75')/Items(2)/FieldValuesAsHtml" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesAsText" type="application/atom+xml;type=entry" title="FieldValuesAsText" href="Web/Lists(guid'7f4df39b-61e1-4657-bb81-8211276e2e75')/Items(2)/FieldValuesAsText" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesForEdit" type="application/atom+xml;type=entry" title="FieldValuesForEdit" href="Web/Lists(guid'7f4df39b-61e1-4657-bb81-8211276e2e75')/Items(2)/FieldValuesForEdit" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/File" type="application/atom+xml;type=entry" title="File" href="Web/Lists(guid'7f4df39b-61e1-4657-bb81-8211276e2e75')/Items(2)/File" />
<link …Run Code Online (Sandbox Code Playgroud) 如何在for循环中声明变量
foreach (System.Xml.XmlNode xmlnode in node)
{
string AMSListName = xmlnode.Attributes["Title"].Value.ToString();
/* the below assignment should be variable for each iteration */
XmlNode ndViewFields + AMSListName = xmlDoc.CreateNode(XmlNodeType.Element,
"ViewFields", "");
}
Run Code Online (Sandbox Code Playgroud)
我该如何实现这一目标?我希望for循环中的每个值都让xmlnode具有不同的名称.这有可能吗?