Reputation: 839
The
:
character , hexadecimal value0x3A
, cannot be included in a name.
I get the above error from the API while parsing an XML body in a RestSharp POST
Request.
What could I do?
string xmlBody = "<soap:Envelope" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
" xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">" +
"<soap:Body> " +
"<MainField " +
" xmlns =\"http://www.w3.org\">" +
"<Username>string</Username> " +
"<Password>string</Password> " +
"<FieldPlace> " +
"<Value1>string</Value1> " +
"<Value2>string</Value2> " +
"</FieldPlace> " +
"</MainField> " +
"</soap:Body> " +
"</soap:Envelope>";
requestPost.AddParameter("text/xml", xmlBody, "text/xml" , ParameterType.RequestBody);
This is the XML
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<MainField>
xmlns ="http://www.w3.org">
<Username>string</Username>
<Password>string</Password>
<FieldPlace>
<Value1>string</Value1>
<Value2>string</Value2>
</FieldPlace>
</MainField>
</soap:Body>
</soap:Envelope>
Upvotes: 0
Views: 763
Reputation: 1992
Please try with this corrected XML and let me know if that works for you.
Couple of points to note:
soap:Envelope element
.MainField
element was closed before adding the namespace.string xmlBody = "<soap:Envelope" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
" xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">" +
"<soap:Body> " +
"<MainField " +
"xmlns=\"http://www.w3.org/2003/05/soap-envelope\" > " +
"<Username>string</Username> " +
"<Password>string</Password> " +
"<FieldPlace> " +
"<Value1>string</Value1> " +
"<Value2>string</Value2> " +
"</FieldPlace> " +
"</MainField> " +
"</soap:Body> " +
"</soap:Envelope>";
I'd also recommend using an alternative method to generate the XML string
, perhaps the System.Xml.XmlWriter
.
Upvotes: 1