ONIX-Data icon indicating copy to clipboard operation
ONIX-Data copied to clipboard

The 'xmlns' attribute is bound to the reserved namespace 'http://www.w3.org/2000/xmlns/'

Open dgil-unedbarbastro opened this issue 4 years ago • 3 comments

Hi, I'm trying to use the ONIX-Data parser with ONIX files from a provider and I'm getting this exception:

  Message: 
    System.ArgumentException : The 'xmlns' attribute is bound to the reserved namespace 'http://www.w3.org/2000/xmlns/'.
  Stack Trace: 
    XmlTextWriter.WriteStartAttribute(String prefix, String localName, String ns)
    XmlDOMTextWriter.WriteStartAttribute(String prefix, String localName, String ns)
    XmlAttribute.WriteTo(XmlWriter w)
    XmlElement.WriteStartElement(XmlWriter w)
    XmlElement.WriteElementTo(XmlWriter writer, XmlElement el)
    XmlElement.WriteTo(XmlWriter w)
    XmlNode.get_OuterXml()
    OnixEnumerator.MoveNext()
    MyService.ParseOnixFile(String filePath) line 42
    MyServiceTests.ParseOnixFile_ShouldReturnOK() line 34
    GenericAdapter`1.GetResult()
    AsyncToSyncAdapter.Await(Func`1 invoke)
    TestMethodCommand.RunTestMethod(TestExecutionContext context)
    TestMethodCommand.Execute(TestExecutionContext context)
    SimpleWorkItem.PerformWork()

The ONIXMessage and all Product xml nodes have the namespace attribute xmlns="http://ns.editeur.org/onix/3.0/reference":

image

If I remove all the xmlns attributes from the file then the parsing works.

I there some way to get the parse working without modifying the original ONIX files?

Thanks in advance. Best Regards, Dani

dgil-unedbarbastro avatar Jun 10 '21 10:06 dgil-unedbarbastro

Namespaces...the bane of anyone who deals with XML. I'll take a look at this issue when I have free time. My first recommendation would be to ask the data provider to stop sending these namespaces (since they're ridiculously pointless), but I know that it's sometimes hard to get such requests granted.

jaerith avatar Jun 11 '21 00:06 jaerith

OK thanks @jaerith, I will try to ask them if they can remove them... probably not ;(

dgil-unedbarbastro avatar Jun 11 '21 06:06 dgil-unedbarbastro

Hmmm...as I start to look over the code, I'm starting to remember how annoying namespaces can really be, especially with the .NET libraries for XML. It'll probably require a little experimentation and time to create an appropriate implementation.

I'll leave this issue open for now, but since I have less availability in my personal time these days, it may be a while before I tackle this one.

jaerith avatar Jun 11 '21 16:06 jaerith