1

I am creating a SLD file and uploading it though the REST API using C#. This SLD file contains some danish characters, but the end result turns out bad. For a test I save the xml file to disk before sending it.

Here is my code

WebResponse response = null;
WebRequest request = null;

request = WebRequest.Create(sldUrl);
request.Credentials = new NetworkCredential(_userName, _password);
request.ContentType = "application/vnd.ogc.sld+xml";
request.Method = "PUT";

sldDocument.Save("c:\\test.sld");

byte[] buffer = Encoding.UTF8.GetBytes(sldDocument.ToString());
Stream reqstr = request.GetRequestStream();
reqstr.Write(buffer, 0, buffer.Length);
reqstr.Close();

response = request.GetResponse();

response.Close();

The local file contains this

<Title>Trådhegn</Title>

But in the SLD file on the server it looks like this

<sld:Title>Trådhegn</sld:Title>

I tried reading the stream as Unicode but that gives me this error

org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 2; The markup in the document preceding the root element must be well-formed.

Im running geoserver 2.7 on a windows machine

  • The second error is usually what you see if you have a BOM character set. Have you set the UTF-8 encoding with <?xml version="1.0" encoding="UTF-8"?>? – Ian Turton Jun 2 '15 at 15:25
  • Yes I have set that. – Jepzen Jun 3 '15 at 6:21
  • Then make sure bom is turned off on your editor – Ian Turton Jun 3 '15 at 13:57
0

I made it work with changing the encoding to ISO-8859-1

byte[] buffer = Encoding.GetEncoding("ISO-8859-1").GetBytes(sldDocument.ToString());

Not sure why but it works..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.