Search code examples
xmlperlnamespacesxml-namespaceslibxml2

How can I ignore a bad xmlns namespace with Perl's LibXML?


I have an XML document that references a namespace that is no available:

<microplateDoc xmlns="http://moleculardevices.com/microplateML">
...my data is here...
</microplateDoc>

I have a script that reads it fine, but only when I delete the two above tags, otherwise it reads it all screwed up. Is it ok just to ignore it? I'm thinking of a writing another script to go through all of my input files and deleting these two lines, but I think there may be a better way?

If I did go through all my datafiles and deleted these two lines, what is the best way to do it with a script? I presume just open each file, search for those terms, delete them, save file, can you think of a better way? thanks.


Solution

  • I don't think there's anything wrong with your namespace there, and I wouldn't go messing with the input files unless you're confident there won't be any unwelcome side-effects. What I think it happening is a common beginner XML-processing mistake: namespaces need to be registered (i.e. bound to a prefix) in your code before you can access the nodes in that namespace.

    http://perl-xml.sourceforge.net/faq/#namespaces_xpath looks like a useful example. I don't generally work with Perl, but I've seen this happen in a bunch of other languages.