0

こんにちはすべて私は次のように打たれた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);

だから誰かが私を助けることができます

4

1 に答える 1

0

「アプリケーションにのみ持っている」という情報だけでは、より動的なものを提供することはできませんが、 Server.MapPath() を使用してすべてのファイルパスを取得できると仮定すると、これは値を取得するために機能するはずですあなたがしたい:

Dictionary<string, string> pairs = new Dictionary<string, string>
{
    {"http://www.irs.gov/efile","ReturnData941.xsd"},
    {"http://schemas.xmlsoap.org/soap/envelope/", "SOAP.xsd"},
    // add as many more of these as you need
};
string schemaLocationValue = 
  string.Join(" ", pairs.Select(p => p.Key + " " + Server.MapPath(p.Value)).ToArray());

次に、そのschemaLocationValue文字列を属性の値として使用しschemaLocationます。

于 2013-01-18T07:31:10.187 に答える