使用web服务保存sharepoint自定义web部件时出现格式正确的XML错误

使用web服务保存sharepoint自定义web部件时出现格式正确的XML错误,sharepoint,sharepoint-2007,moss,Sharepoint,Sharepoint 2007,Moss,我创建了一个具有自定义集合属性(选项卡)的自定义web部件。在编辑模式下(通过浏览器)编辑和保存自定义特性时,web部件工作正常。我想使用web服务更新我的自定义web部件,因此我导出了该web部件并获取了xml内容并按原样传递了它(因此我可以轻松地测试它),但出现了一个错误 The file you imported is not valid. Verify that the file is a Web Part description file (*.webpart or *.dwp) a

我创建了一个具有自定义集合属性(选项卡)的自定义web部件。在编辑模式下(通过浏览器)编辑和保存自定义特性时,web部件工作正常。我想使用web服务更新我的自定义web部件,因此我导出了该web部件并获取了xml内容并按原样传递了它(因此我可以轻松地测试它),但出现了一个错误

The file you imported is not valid. 
Verify that the file is a Web Part description file (*.webpart or *.dwp) and that it contains well-formed XML.
我已经使用在线xml验证器验证了xml,并删除了此语句

<?xml version="1.0" encoding="utf-16"?>

根据XML验证器,这是导致formex XML不好的原因之一,但仍然没有运气,因此发生了相同的错误

有什么想法吗?我无法找出XML的错误,特别是在Tabs属性上

代码:

    string webPartXml = string.Empty;
    string pageUrl = currenturl;

        Guid storageKey = new Guid(webpartid);

        using (StreamReader sr = new StreamReader(@"C:\tab.txt"))
        {            
            webPartXml = sr.ReadToEnd();                
        }
        webPartXml = webPartXml.Replace("&lt;", "<").Replace("&gt;",">");

        try
        {
            svc.SaveWebPart2(pageUrl, storageKey, webPartXml, WebpartpagesSvc.Storage.Shared, false);
        }catch(Exception err)
        {
            throw;
        }
string webPartXml=string.Empty;
字符串pageUrl=currenturl;
Guid storageKey=新Guid(Web部件ID);
使用(StreamReader sr=newstreamreader(@“C:\tab.txt”))
{            
webPartXml=sr.ReadToEnd();
}
webPartXml=webPartXml.Replace(“,”);
尝试
{
svc.SaveWebPart2(pageUrl、storageKey、webPartXml、WebpartpagesSvc.Storage.Shared、false);
}捕获(异常错误)
{
投
}
Tab.txt(Tab.webpart)


无法导入此web部件。
没有一个
0
错误的
符合事实的
符合事实的
?xml version=“1.0”encoding=“utf-16”?
选项卡xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance“xmlns:xsd=”http://www.w3.org/2001/XMLSchema"
TabInfo
标签
标题HTML测试/标题
/标签
/TabInfo
/标签
0
符合事实的
符合事实的
导航
错误的
标签
典型的
符合事实的
对于选项卡示例。
符合事实的
全部的
NotSet
错误消息

base {System.SystemException} = {"Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown."}
InnerText = "The file you imported is not valid. Verify that the file is a Web Part description file (*.webpart or *.dwp) and that it contains well-formed XML."
InnerXml = "<errorstring xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">The file you imported is not valid. Verify that the file is a Web Part description file (*.webpart or *.dwp) and that it contains well-formed XML.</errorstring>"
base{System.SystemException}={“引发了类型为'Microsoft.SharePoint.SoapServer.SoapServerException'的异常。”}
InnerText=“导入的文件无效。请验证该文件是否为Web部件说明文件(*.webpart或*.dwp),以及是否包含格式正确的XML。”
InnerXml=“导入的文件无效。请验证该文件是否为Web部件描述文件(*.webpart或*.dwp),以及是否包含格式正确的XML。”

我认为,当您试图将xml还原为原始xml时,会破坏它。您真的需要这行代码吗:

webPartXml = webPartXml.Replace("&lt;", "<").Replace("&gt;",">"); 
webPartXml=webPartXml.Replace(“,”);
如果你移除它会发生什么? 如果不起作用,我建议将值包装在CDATA标记中,以便转义xml:

string startTabProperty = @"<property name=""Tabs"" type=""Test.Tabs, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c9e6068352095bx6"">";
string endTabProperty = "></property>"; //Note the >< in order to identify correct place
webPartXml = webPartXml.Replace("&lt;", "<").Replace("&gt;",">"); 
webPartXml = webPartXml.Replace(startTabProperty, startTabProperty + "<![CDATA[");
webPartXml = webPartXml.Replace(endTabProperty , ">" + "]]>" + "</property>");
string startTabProperty=@”;
字符串endTabProperty=“>”//注意><以确定正确的位置
webPartXml=webPartXml.Replace(“,”);
webPartXml=webPartXml.Replace(startTabProperty,startTabProperty++“]]>“+”);

祝你好运

在模块的
元素.xml中写入下面的代码
&在
listUrl
TitleUrl

<Module>
<File>
<AllUsersWebPart WebPartZoneID="wzMain" WebPartOrder="2">
    <![CDATA[
    <webParts>
    <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
    <metaData>
    <type name="Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
    <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
    </metaData>
    <data>
    <properties>
    <property name="ShowWithSampleData" type="bool">False</property>
    <property name="Default" type="string" />
    <property name="NoDefaultStyle" type="string" null="true" />
    <property name="CacheXslStorage" type="bool">True</property>
    <property name="ViewContentTypeId" type="string" />
    <property name="XmlDefinitionLink" type="string" />
    <property name="ManualRefresh" type="bool">False</property>
    <property name="ListUrl" type="string" >Lists/Employee_list</property>
    <property name="TitleUrl" type="string">/Lists/Employee_list</property>
    </properties>
    </data>
    </webPart>
    </webParts>
    ]]>
    </AllUsersWebPart>
    </File>
  </Module>

无法导入此Web部件。
错误的
符合事实的
错误的
名单/员工名单
/名单/员工名单
]]>
<Module>
<File>
<AllUsersWebPart WebPartZoneID="wzMain" WebPartOrder="2">
    <![CDATA[
    <webParts>
    <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
    <metaData>
    <type name="Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
    <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
    </metaData>
    <data>
    <properties>
    <property name="ShowWithSampleData" type="bool">False</property>
    <property name="Default" type="string" />
    <property name="NoDefaultStyle" type="string" null="true" />
    <property name="CacheXslStorage" type="bool">True</property>
    <property name="ViewContentTypeId" type="string" />
    <property name="XmlDefinitionLink" type="string" />
    <property name="ManualRefresh" type="bool">False</property>
    <property name="ListUrl" type="string" >Lists/Employee_list</property>
    <property name="TitleUrl" type="string">/Lists/Employee_list</property>
    </properties>
    </data>
    </webPart>
    </webParts>
    ]]>
    </AllUsersWebPart>
    </File>
  </Module>