Well-formed XML error when saving the sharepoint custom web part using web services -
Well-formed XML error when saving the sharepoint custom web part using web services -
i created custom web part has custom collection property (tabs). web part works when edit , save custom property on edit mode (via browser). want update custom web part using web services,so exported web part , took xml content , passed (so test it), error occured
the file imported not valid. verify file web part description file (*.webpart or *.dwp) , contains well-formed xml.
i have validated xml using online xml validator , removed statement
<?xml version="1.0" encoding="utf-16"?>
as 1 causing not well-formex xml according xml validator, still no luck, same error occured.
any ideas? not figured out what's wrong xml specially on tabs property.
code:
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("<", "<").replace(">",">"); seek { svc.savewebpart2(pageurl, storagekey, webpartxml, webpartpagessvc.storage.shared, false); }catch(exception err) { throw; }
tab.txt (tab.webpart)
<webparts> <webpart xmlns="http://schemas.microsoft.com/webpart/v3"> <metadata> <type name="test.tabwebpart, test, version=1.0.0.0, culture=neutral, publickeytoken=c9e6068352095bx6" /> <importerrormessage>cannot import web part.</importerrormessage> </metadata> <data> <properties> <property name="chrometype" type="chrometype">none</property> <property name="height" type="unit" /> <property name="panelheight" type="int">0</property> <property name="showroundedtabs" type="bool">false</property> <property name="allowzonechange" type="bool">true</property> <property name="allowedit" type="bool">true</property> <property name="tabs" type="test.tabs, test, version=1.0.0.0, culture=neutral, publickeytoken=c9e6068352095bx6"><?xml version="1.0" encoding="utf-16"?> <tabs xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <tabinfo> <tab> <title>html-testing</title> </tab> </tabinfo> </tabs></property> <property name="catalogiconimageurl" type="string" /> <property name="panelwidth" type="int">0</property> <property name="allowconnect" type="bool">true</property> <property name="allowclose" type="bool">true</property> <property name="helpmode" type="helpmode">navigate</property> <property name="childtab" type="system.collections.specialized.namevaluecollection, system, version=2.0.0.0, culture=neutral, publickeytoken=b77a5c561934ebb9" /> <property name="hidden" type="bool">false</property> <property name="title" type="string">tab </property> <property name="chromestate" type="chromestate">normal</property> <property name="allowhide" type="bool">true</property> <property name="description" type="string">for tab sample.</property> <property name="allowminimize" type="bool">true</property> <property name="titleurl" type="string" /> <property name="width" type="unit" /> <property name="exportmode" type="exportmode">all</property> <property name="direction" type="direction">notset</property> <property name="helpurl" type="string" /> <property name="titleiconimageurl" type="string" /> </properties> </data> </webpart> </webparts>
error message
base {system.systemexception} = {"exception of type 'microsoft.sharepoint.soapserver.soapserverexception' thrown."} innertext = "the file imported not valid. verify file web part description file (*.webpart or *.dwp) , contains well-formed xml." innerxml = "<errorstring xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">the file imported not valid. verify file web part description file (*.webpart or *.dwp) , contains well-formed xml.</errorstring>"
i think when seek restore xml original breaks it. need line of code:
webpartxml = webpartxml.replace("<", "<").replace(">",">");
what happens if remove it? if doesnt work, recommend wrapping value in cdata-tag in order escape xml:
string starttabproperty = @"<property name=""tabs"" type=""test.tabs, test, version=1.0.0.0, culture=neutral, publickeytoken=c9e6068352095bx6"">"; string endtabproperty = "></property>"; //note >< in order identify right place webpartxml = webpartxml.replace("<", "<").replace(">",">"); webpartxml = webpartxml.replace(starttabproperty, starttabproperty + "<![cdata["); webpartxml = webpartxml.replace(endtabproperty , ">" + "]]>" + "</property>");
good luck!
sharepoint sharepoint-2007 moss
Comments
Post a Comment