大家好,我正在动态创建一个 XML 文件,我遇到了以下问题,我有以下代码,它将分配架构位置,如下所示
XmlAttribute attr5 = doc.CreateAttribute("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance");
string strXSDPath = "http://www.irs.gov/efile ";
strXSDPath = strXSDPath + Server.MapPath("ReturnData941.xsd");
attr5.Value = strXSDPath;
returnData.Attributes.Append(attr5);
这工作正常,这在我的 XML 文件中给出如下
<?xml version="1.0" encoding="UTF-8"?>
<SOAP:Envelope xmlns="http://www.irs.gov/efile"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:efile="http://www.irs.gov/efile"
***xsi:schemaLocation="http://www.irs.gov/efile ReturnData941.xsd*"** />
但是在这里,我想在单个中具有多个模式位置,如下所示
xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/../message/SOAP.xsd
http://www.irs.gov.efile../message/efileMessage.xsd"
这是我的 XML 生成代码
XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
doc.AppendChild(docNode);
//XmlNode returnData = doc.CreateElement("SOAP");
XmlElement returnData = doc.CreateElement("SOAP", "Envelope", "http://www.irs.gov/efile");
XmlAttribute attr = doc.CreateAttribute("xmlns");
attr.Value = "http://www.irs.gov/efile";
returnData.Attributes.Append(attr);
XmlAttribute attr1 = doc.CreateAttribute("xmlns:xsi");
attr1.Value = "http://www.w3.org/2001/XMLSchema-instance";
returnData.Attributes.Append(attr1);
XmlAttribute attr3 = doc.CreateAttribute("xmlns:SOAP");
attr3.Value = "http://schemas.xmlsoap.org/soap/envelope/";
returnData.Attributes.Append(attr3);
XmlAttribute attr4 = doc.CreateAttribute("xmlns:efile");
attr4.Value = "http://www.irs.gov/efile";
returnData.Attributes.Append(attr4);
XmlAttribute attr5 = doc.CreateAttribute("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance");
attr5.Value = strXSDPath;
returnData.Attributes.Append(attr5);
所以有人可以帮助我吗