2016-02-06 2 views
0

У меня есть код ниже.Как удалить xmlns tag

namespace IrancellSmsServer 
{ 

      [WebService(Namespace = "http://www.csapi.org/schema/parlayx/data/sync/v1_0/local")] 

    public class SoapServer : System.Web.Services.WebService 
    { 

     [SoapDocumentMethod(Action = "",ParameterStyle = SoapParameterStyle.Bare)] 


     [WebMethod] 
     public syncOrderRelationResponse syncOrderRelation(
      Sync.UserID userID, 
      string spID, 
      string productID, 
      string serviceID, 
      string serviceList, 
      int updateType, 
      string updateTime, 
      string updateDesc, 
      string effectiveTime, 
      string expiryTime, 
      item[] extensionInfo 
      ) 
     { 


      syncOrderRelationResponse a = new syncOrderRelationResponse(); 
      a.result = 0; 
      a.resultDescription = "OK"; 

      return a; 
     } 

, который генерирует это для меня:

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <userID xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local"> 
     <ID xmlns="">string</ID> 
     <type xmlns="">int</type> 
    </userID> 
    <spID xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">string</spID> 
    <productID xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">string</productID> 
    <serviceID xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">string</serviceID> 
    <serviceList xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">string</serviceList> 
    <updateType xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">int</updateType> 
    <updateTime xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">string</updateTime> 
    <updateDesc xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">string</updateDesc> 
    <effectiveTime xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">string</effectiveTime> 
    <expiryTime xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">string</expiryTime> 
    <extensionInfo xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local"> 
     <item> 
     <key xmlns="">string</key> 
     <value xmlns="">string</value> 
     </item> 
     <item> 
     <key xmlns="">string</key> 
     <value xmlns="">string</value> 
     </item> 
    </extensionInfo> 
    </soap:Body> 
</soap:Envelope> 

Я хочу, чтобы те xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local быть удалены. Я был в порядке, пока не добавил эту строку

[SoapDocumentMethod(Action = "",ParameterStyle = SoapParameterStyle.Bare)] 

после того, как я добавил строку, я начал получать дополнительные пространства имен;

, что я хочу, чтобы генерировать как это:

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <userID> 
     <ID xmlns="">string</ID> 
     <type xmlns="">int</type> 
    </userID> 
    <spID>string</spID> 
    <productID>string</productID> 
    <serviceID>string</serviceID> 
    <serviceList>string</serviceList> 
    <updateType>int</updateType> 
    <updateTime>string</updateTime> 
    <updateDesc>string</updateDesc> 
    <effectiveTime>string</effectiveTime> 
    <expiryTime>string</expiryTime> 
    <extensionInfo> 
     <item> 
     <key xmlns="">string</key> 
     <value xmlns="">string</value> 
     </item> 
     <item> 
     <key xmlns="">string</key> 
     <value xmlns="">string</value> 
     </item> 
    </extensionInfo> 
    </soap:Body> 
</soap:Envelope> 

, что я должен делать. спасибо.

+0

Возможный дубликат [Как удалить все пространства имен из XML с C#?] (Http://stackoverflow.com/questions/987135/how-to- remove-all-namespaces-from-xml-with-c) –

ответ

0

Проверить this answer и попробовать рекурсивную функцию:

//Implemented based on interface, not part of algorithm 
public static string RemoveAllNamespaces(string xmlDocument) 
{ 
    XElement xmlDocumentWithoutNs = RemoveAllNamespaces(XElement.Parse(xmlDocument)); 

    return xmlDocumentWithoutNs.ToString(); 
} 

//Core recursion function 
private static XElement RemoveAllNamespaces(XElement xmlDocument) 
    { 
     if (!xmlDocument.HasElements) 
     { 
      XElement xElement = new XElement(xmlDocument.Name.LocalName); 
      xElement.Value = xmlDocument.Value; 

      foreach (XAttribute attribute in xmlDocument.Attributes()) 
       xElement.Add(attribute); 

      return xElement; 
     } 
     return new XElement(xmlDocument.Name.LocalName, xmlDocument.Elements().Select(el => RemoveAllNamespaces(el))); 
    } 
+0

как это реализовать в моем коде .sorry? –

+0

Просто передайте XML-документ этому методу –