Re: [xml] question about how to set namespace in libxml
- From: Michael Ludwig <milu71 gmx de>
- To: xml gnome org
- Subject: Re: [xml] question about how to set namespace in libxml
- Date: Sat, 5 Mar 2011 14:52:35 +0100
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]