Re: [xml] Can I read namespace URIs as regular attributes?
- From: Michael Ludwig <mlu as-guides com>
- To: xml gnome org
- Subject: Re: [xml] Can I read namespace URIs as regular attributes?
- Date: Wed, 02 Sep 2009 11:23:23 +0200
Jianqing Zhang schrieb:
I'm trying to read all namespace URIs by go through all attributes of
the root element. Can I read them as regular attributes?
Jianqing,
I don't know the C API, but in general, a parser may have a flag to
turn namespace-awareness on or off.
I'm not sure LibXML2 has this flag, though; namespace-awareness may
be on by default. And in that case, you probably cannot read them as
regular attributes, because they're made available through a different
part of the API.
After coding the following sample in Perl, I'm unsure what the rule is
for namespaces and attributes - because here I can see the namespace
attributes not only using $node->getNamespaces(), but alos using
$node->attributes().
use strict;
use warnings;
use XML::LibXML;
my $parser = XML::LibXML->new;
my $doc = $parser->parse_string(
q{<Urmel xmlns="urn:urmel" xmlns:milu="urn:milu" x="3"/>});
print "\ngetNamespaces:\n";
print $_->name, "\t", $_->value, "\n"
for $doc->documentElement->getNamespaces;
print "\nattributes:\n";
print $_->name, "\t", $_->value, "\n"
for $doc->documentElement->attributes;
milu colinux:~/Werkstatt/perl/xml > perl xml-libxml-ns.pl
getNamespaces:
xmlns urn:urmel
xmlns:milu urn:milu
attributes:
x 3
xmlns urn:urmel
xmlns:milu urn:milu
--
Michael Ludwig
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]