27

This is in the context of Web Services (client end). I need to interface with a back-end system (Java) and it is a requirement to transmit some control characters in the  and  range.

I'm well aware that XML 1.0 doesn't support this, but am interested to know if the .NET 4 platform or .NET 4.5 web services framework support conversations in XML 1.1.

RichardTheKiwi
  • 105,798
  • 26
  • 196
  • 262

2 Answers2

32

No, it doesn't look like XmlReader (the core of much of the XML support in .NET) supports 1.1:

using System;
using System.IO;
using System.Xml;

class Program
{
    static void Main(string[] args)
    {
        string xml = "<?xml version=\"1.1\" ?><tag>&#x1</tag>";
        var reader = XmlReader.Create(new StringReader(xml));
        while (reader.Read());
    }
}

Output:

Unhandled Exception: System.Xml.XmlException: Version number '1.1' is invalid.
Line 1, position 16.

I've looked at XmlReaderSettings to see if anything there would help, but I don't think it does. Basically I think you're stuck for the moment :(

EDIT: Reading around XML 1.1 a bit, it looks like it's not widely deployed or recommended, so I'm not particularly surprised that it's not supported in .NET 4.5. My guess is that it never will be, given that it's not a particularly new recommendation. The most recent version is the 2nd edition which dates back to 2006. If it's not supported 7 years later, I suspect there'd have to be some significant event to make it worth supporting in the future.

Pang
  • 9,564
  • 146
  • 81
  • 122
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
10

I am sure this is not the best option but if you download IKVM you can use java classes in your .Net code after referencing a few assemblies (really .Net code :) )

var fXmlFile = new java.io.File(xmlfile);

var dbFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
var dBuilder = dbFactory.newDocumentBuilder();

var doc = dBuilder.parse(fXmlFile);
var nList = doc.getElementsByTagName("controlcharacters");

var chars = nList.item(0).getTextContent().ToCharArray();

XML File:

<?xml version="1.1" ?>
<root>
    <controlcharacters>&#14;&#15;</controlcharacters>
</root>
Pang
  • 9,564
  • 146
  • 81
  • 122
I4V
  • 34,891
  • 6
  • 67
  • 79
  • Very interesting bridging to Java. But how does that translate to WebService API calls? Unlike C classes, I cannot just overwrite a .Net class (XMLWriter/XMLReader) with pointers to the Java equivalents – RichardTheKiwi Jun 24 '13 at 21:38
  • @RichardTheKiwi Of course, you will have to use java counterparts of them (javax.xml.parsers) in c# as above. I am not a java programmer, I adapted (and tested) above code from the first sample I found on internet. But I guess, a simple java client for consuming webservices can also be utilized easily. – I4V Jun 25 '13 at 18:49
  • 1
    @RichardTheKiwi As a side note: using IKVM doesn't require any java installation on the client machine. Nothing different than referencing a third party Dll. So I wouldn't say `bridging to Java`. More like .Net implemantation of Java libraries. – I4V Jun 25 '13 at 19:02