microsoft / XLIFF2-Object-Model

If you’re looking to store localization data and propagate it through your localization pipeline allowing tools to interoperate then you may want to use the XLIFF 2.0 object model. The XLIFF 2.0 object model implements the OASIS Standard for the XLIFF 2.0 specification as defined at http://docs.oasis-open.org/xliff/xliff-core/v2.0/xliff-core-v2.0.html.
Other
86 stars 25 forks source link

The character '/' in namespace URIs is not allowed by the serializer #16

Closed ysavourel closed 5 years ago

ysavourel commented 8 years ago

When I read the file below, the Deserializer works fine. But if I try to serialize the document read, I get this error:

Unhandled Exception: Localization.Xliff.OM.Exceptions.InvalidXmlSpecifierException: A valid XML prefix, namespace, and local name must be specified for the entity named 'version'. ---> System.Xml.XmlException: The '/' character, hexadecimal value 0x2F, cannot be included in a name.

If I replace the '/' in the ITS namespace URI by '_' all works fine.

Here is the example file:

<?xml` version="1.0"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="en-us"
 xmlns:its="http://www.w3.org/2005/11/its" its:version="2.0">
 <file id="f1" original="test.html">
  <unit id="tu1">
   <segment>
    <source>Test</source>
   </segment>
  </unit>
 </file>
</xliff>

And here is the code:

class Program
{
    static void Main(string[] args)
    {
        using (IO.FileStream stream = new IO.FileStream(args[0], IO.FileMode.Open))
        {
            XliffReader reader = new XliffReader();
            XliffDocument doc = reader.Deserialize(stream);
            System.Console.WriteLine("cont 0 = " + doc.Files[0].Containers[0].Id);
            String path2 = "C:\\temp\\out.xlf";
            using (IO.FileStream stream2 = new IO.FileStream(path2, IO.FileMode.Create, IO.FileAccess.Write))
            {
                XliffWriter writer = new XliffWriter();
                writer.Serialize(stream2, doc);
            }
        }
    }
}
ysavourel commented 8 years ago

I believe the issue is coming from the line below in XliffWriter.cs

if (!checkLocalOnly)
{
    XmlConvert.VerifyNCName(prefix);
    XmlConvert.VerifyName(ns);              <-- issue
}

It should check for a valid URI rather than a valid XML name. See https://www.w3.org/TR/REC-xml-names/#concepts:

[Definition: An XML namespace is identified by a URI reference [RFC3986]; element and attribute names may be placed in an XML namespace using the mechanisms described in this specification.]

RyanKing77 commented 8 years ago

Thanks for reporting this issue. If you'd like to contribute a fix, please do so in your fork and create a pull request. Otherwise, we will log a bug and prioritize a fix appropriately.