libxml++ r179 - in trunk: . examples/dom_parser libxml++ libxml++/nodes
- From: murrayc svn gnome org
- To: svn-commits-list gnome org
- Subject: libxml++ r179 - in trunk: . examples/dom_parser libxml++ libxml++/nodes
- Date: Thu, 14 Aug 2008 07:19:04 +0000 (UTC)
Author: murrayc
Date: Thu Aug 14 07:19:04 2008
New Revision: 179
URL: http://svn.gnome.org/viewvc/libxml++?rev=179&view=rev
Log:
2008-08-14 Murray Cumming <murrayc murrayc com>
* examples/dom_parser/Makefile.am:
* examples/dom_parser/example_with_namespace.xml:
Added an example using namespace prefixes, from bug
#547689.
* examples/dom_parser/main.cc: Comment out the call to set_validate(),
because that example does not have a DTD.
Show the namespace prefixes in the output.
* libxml++/attribute.cc: get_value(): Use xmlGetNsProp() instead of
xmlGetProp(), so we don't ignore the namespace prefix, so we get
the correct value.
Bug #547689 (Sergei Fedorov)
Added:
trunk/examples/dom_parser/example_with_namespace.xml
Modified:
trunk/ChangeLog
trunk/examples/dom_parser/Makefile.am
trunk/examples/dom_parser/main.cc
trunk/libxml++/attribute.cc
trunk/libxml++/attribute.h
trunk/libxml++/nodes/element.cc
trunk/libxml++/nodes/node.cc
Modified: trunk/examples/dom_parser/Makefile.am
==============================================================================
--- trunk/examples/dom_parser/Makefile.am (original)
+++ trunk/examples/dom_parser/Makefile.am Thu Aug 14 07:19:04 2008
@@ -6,4 +6,4 @@
#List of source files needed to build the executable:
example_SOURCES = main.cc
-EXTRA_DIST = example.xml example_invalid.xml example.dtd
+EXTRA_DIST = example.xml example_with_namespace.xml example_invalid.xml example.dtd
Added: trunk/examples/dom_parser/example_with_namespace.xml
==============================================================================
--- (empty file)
+++ trunk/examples/dom_parser/example_with_namespace.xml Thu Aug 14 07:19:04 2008
@@ -0,0 +1,6 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<xmi:XMI xmi:version='2.1' timestamp='Tue Aug 12 23:29:35 MSD 2008' xmlns:uml='http://schema.omg.org/spec/UML/2.0' xmlns:xmi='http://schema.omg.org/spec/XMI/2.1'>
+ <ownedAttribute xmi:type='uml:Property' type='_10_5_1_48330b1a_1210846583577_94225_312'/>
+</xmi:XMI>
+
Modified: trunk/examples/dom_parser/main.cc
==============================================================================
--- trunk/examples/dom_parser/main.cc (original)
+++ trunk/examples/dom_parser/main.cc Thu Aug 14 07:19:04 2008
@@ -44,13 +44,17 @@
if(nodeText && nodeText->is_white_space()) //Let's ignore the indenting - you don't always want to do this.
return;
- Glib::ustring nodename = node->get_name();
+ const Glib::ustring nodename = node->get_name();
if(!nodeText && !nodeComment && !nodename.empty()) //Let's not say "name: text".
{
print_indentation(indentation);
- std::cout << "Node name = " << node->get_name() << std::endl;
- std::cout << "Node name = " << nodename << std::endl;
+
+ const Glib::ustring namespace_prefix = node->get_namespace_prefix();
+ if(namespace_prefix.empty())
+ std::cout << "Node name = " << nodename << std::endl;
+ else
+ std::cout << "Node name = " << namespace_prefix << ":" << nodename << std::endl;
}
else if(nodeText) //Let's say when it's text. - e.g. let's say what that white space is.
{
@@ -88,14 +92,18 @@
{
const xmlpp::Attribute* attribute = *iter;
print_indentation(indentation);
- std::cout << " Attribute " << attribute->get_name() << " = " << attribute->get_value() << std::endl;
+
+ const Glib::ustring namespace_prefix = attribute->get_namespace_prefix();
+ if(namespace_prefix.empty())
+ std::cout << " Attribute " << attribute->get_name() << " = " << attribute->get_value() << std::endl;
+ else
+ std::cout << " Attribute " << namespace_prefix << ":" << attribute->get_name() << " = " << attribute->get_value() << std::endl;
}
const xmlpp::Attribute* attribute = nodeElement->get_attribute("title");
if(attribute)
{
std::cout << "title found: =" << attribute->get_value() << std::endl;
-
}
}
@@ -123,7 +131,7 @@
{
#endif //LIBXMLCPP_EXCEPTIONS_ENABLED
xmlpp::DomParser parser;
- parser.set_validate();
+ //parser.set_validate();
parser.set_substitute_entities(); //We just want the text to be resolved/unescaped automatically.
parser.parse_file(filepath);
if(parser)
Modified: trunk/libxml++/attribute.cc
==============================================================================
--- trunk/libxml++/attribute.cc (original)
+++ trunk/libxml++/attribute.cc Thu Aug 14 07:19:04 2008
@@ -27,7 +27,11 @@
Glib::ustring Attribute::get_value() const
{
- xmlChar *value = xmlGetProp(cobj()->parent, cobj()->name);
+ const xmlChar* ns_prefix = NULL;
+ if(cobj()->ns)
+ ns_prefix = cobj()->ns->prefix;
+
+ xmlChar *value = xmlGetNsProp(cobj()->parent, cobj()->name, ns_prefix);
Glib::ustring retn = value ? (char *)value : "";
xmlFree(value);
return retn;
Modified: trunk/libxml++/attribute.h
==============================================================================
--- trunk/libxml++/attribute.h (original)
+++ trunk/libxml++/attribute.h Thu Aug 14 07:19:04 2008
@@ -30,8 +30,21 @@
explicit Attribute(_xmlNode* node);
virtual ~Attribute();
+ //TODO: Can we remove this and just use Node::get_name()?
+
+ /** Get the name of this attribute.
+ * See also Node::get_namespace_prefix() and Node::get_namespace_uri()
+ * @returns The attributes's name.
+ */
Glib::ustring get_name() const;
+
+ /** Get the value of this attribute.
+ * @returns The attributes's value.
+ */
Glib::ustring get_value() const;
+
+ /** Set the value of this attribute.
+ */
void set_value(const Glib::ustring& value);
///Access the underlying libxml implementation.
Modified: trunk/libxml++/nodes/element.cc
==============================================================================
--- trunk/libxml++/nodes/element.cc (original)
+++ trunk/libxml++/nodes/element.cc Thu Aug 14 07:19:04 2008
@@ -39,7 +39,7 @@
Attribute* Element::get_attribute(const Glib::ustring& name,
const Glib::ustring& ns_prefix) const
{
- if (ns_prefix.empty())
+ if(ns_prefix.empty())
{
xmlAttr* attr = xmlHasProp(const_cast<xmlNode*>(cobj()), (const xmlChar*)name.c_str());
if( attr )
Modified: trunk/libxml++/nodes/node.cc
==============================================================================
--- trunk/libxml++/nodes/node.cc (original)
+++ trunk/libxml++/nodes/node.cc Thu Aug 14 07:19:04 2008
@@ -348,7 +348,7 @@
return Glib::ustring();
}
- if(impl_ && impl_->ns && impl_->ns->href)
+ if(impl_ && impl_->ns && impl_->ns->href)
return (char*)impl_->ns->href;
else
return Glib::ustring();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]