大家好,我正在创建一个动态生成XML文件的应用程序。在这里,我想将schemalocation和XSI添加到XML Root中,我该如何做到这一点。我想补充以下几点
xmlns="http://www.irs.gov/efile"
xsi:SchemaLocation="http://www.irs.goc/efile ReturnData941.xsd"和
xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance"这是我动态生成的样例XML代码
XmlDocument doc = new XmlDocument();
XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
doc.AppendChild(docNode);
XmlNode returnData = doc.CreateElement("ReturnData");
XmlAttribute documnetCount = doc.CreateAttribute("documentCount"); // after this i would like to add that schema
returnData.Attributes.Append(documnetCount);所以我应该像下面这样得到我的XML
<?xml version="1.0" encoding="UTF-8"?>
<ReturnData documentCount="" xsi:SchemaLocation="http://www.irs.goc/efile ReturnData941.xsd" xmlns="http://www.irs.gov/efile" xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance" />发布于 2011-12-16 15:57:07
我认为您只需要添加一个属性,比如
XmlAttribute attr = doc.CreateAttribute("xsi", "schemaLocation", " ");
attr.Value = "http://www.irs.goc/efile ReturnData941.xsd";
returnData.Attributes.Append(attr);发布于 2011-12-16 18:45:30
我想知道这是不是处理事情的最好方法?许多验证API允许您单独指定模式位置和实例文档位置,这可能比将模式位置存储在实例中更有效。
总之,我对xsi:schemaLocation持怀疑态度。如果要验证实例,通常是因为您不信任它,如果不信任它,为什么要信任它的xsi:schemaLocation呢?
https://stackoverflow.com/questions/8530993
复制相似问题