Re: [xml] Can I read namespace URIs as regular attributes?
- From: Jianqing Zhang <arrow jianqing gmail com>
- To: Michael Ludwig <mlu as-guides com>
- Cc: xml gnome org
- Subject: Re: [xml] Can I read namespace URIs as regular attributes?
- Date: Wed, 2 Sep 2009 17:39:24 -0500
Thanks Michael. I'm using C++ and have not figured it out. I'm
wondering how I can get these namespace URIs. information
On Wed, Sep 2, 2009 at 4:23 AM, Michael Ludwig<mlu as-guides com> wrote:
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
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]