Dan Quach schrieb am 01.03.2011 um 12:05 (-0800): > Currently I am reading in the following xml document (through a ruby > wrapper) > LibXML::XML::Document.string( saml_plain) > > <ds:SignedInfo> > <ds:CanonicalizationMethod Algorithm=' > http://www.w3.org/2001/10/xml-exc-c14n#'/> > […] > </ds:SignedInfo>
That document is not namespace-well-formed. > The problem when it is read in that all of the ds namespaces are > stripped and errors occur This is sort of a fallback parsing as namespaces are an add-on to XML, which is not in the XML recommendation. > Is there a way I can set the 'ds' namespace as ' > http://www.w3.org/2000/09/xmldsig#' so it would be read in as: > <ds:SignedInfo xmlns:ds="http://www.w3.org/2000/09/xmldig#"> > […] > </ds:SignedInfo> You can simply edit your document. If you want to edit your document programmatically, you could parse it using SAX with namespace-awareness turned off and have a filter insert an xmlns:ds attribute, which in non-NS mode really is just an attribute with a name that happens to contain a colon. You would then build a document *with* namespaces from the result of that preprocessing step. Well, I'm not quite sure this is possible with LibXML2. It is with Java Xerces ( void setDoNamespaces(const bool) ) [1], but I can't find such an option for Perl's LibXML2 bindings. [2] Don't know the C API. Anyone? Namespace ignorance does not seem to be possible with the XmlReader interface. I'm saying this because I can't find the option in the Perl interface [3]. You could also use a non-XML process, such as Perl and regular expressions to fix thousands of such documents. -- Michael Ludwig [1] http://xerces.apache.org/xerces-c/program-sax-3.html [2] http://search.cpan.org/~pajas/XML-LibXML-1.70/lib/XML/LibXML/Parser.pod [3] http://search.cpan.org/~pajas/XML-LibXML-1.70/lib/XML/LibXML/Reader.pod _______________________________________________ xml mailing list, project page http://xmlsoft.org/ [email protected] http://mail.gnome.org/mailman/listinfo/xml
