zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #03184
[Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
Chris Hillery has proposed merging lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba.
Requested reviews:
Zorba Coders (zorba-coders)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/get-namespace-bindings/+merge/87187
Exposes Item::getNamespaceBindings() through the public API. This is necessary for the CSX module.
I am not sure whether defining the NsBindings typedef and NsScoping enum on the Item class itself was a good idea or not.
--
https://code.launchpad.net/~zorba-coders/zorba/get-namespace-bindings/+merge/87187
Your team Zorba Coders is requested to review the proposed merge of lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba.
=== modified file 'doc/cxx/examples/simple.cpp'
--- doc/cxx/examples/simple.cpp 2011-06-14 14:21:49 +0000
+++ doc/cxx/examples/simple.cpp 2011-12-31 09:17:24 +0000
@@ -33,14 +33,14 @@
std::cout << lQuery << std::endl;
- return true;
+ return true;
}
bool
example_2(Zorba* aZorba)
{
- XQuery_t lQuery = aZorba->compileQuery("1+2");
+ XQuery_t lQuery = aZorba->compileQuery("1+2");
Iterator_t lIterator = lQuery->iterator();
lIterator->open();
@@ -53,7 +53,7 @@
lIterator->close();
- return true;
+ return true;
}
@@ -61,7 +61,7 @@
example_3(Zorba* aZorba)
{
- XQuery_t lQuery = aZorba->compileQuery("1 div 0");
+ XQuery_t lQuery = aZorba->compileQuery("1 div 0");
try {
std::cout << lQuery << std::endl;
} catch ( ZorbaException& e ) {
@@ -69,7 +69,7 @@
return true;
}
- return false;
+ return false;
}
@@ -125,9 +125,7 @@
bool
example_7()
{
-
std::cout << Zorba::version() << std::endl;
-
return true;
}
@@ -246,7 +244,8 @@
bool
example_12(Zorba* aZorba)
{
- XQuery_t lQuery = aZorba->compileQuery("<a><b attr='1'/><b attr='2'/></a>");
+ XQuery_t lQuery = aZorba->compileQuery
+ ("<a xmlns:foo='http://www.zorba-xquery.com/'><b attr='1' xmlns:bar='http://www.zorba-xquery.com/uri2'/><b attr='2'/></a>");
Iterator_t lIterator = lQuery->iterator();
lIterator->open();
@@ -263,16 +262,22 @@
Item lNodeName;
lChild.getNodeName(lNodeName);
std::cout << "node name " << lNodeName.getStringValue() << std::endl;
+
Iterator_t lAttrIter = lChild.getAttributes();
-
lAttrIter->open();
-
Item lAttr;
while (lAttrIter->next(lAttr))
{
std::cout << " attribute value " << lAttr.getStringValue() << std::endl;
}
lAttrIter->close();
+
+ Item::NsBindings lBindings;
+ lChild.getNamespaceBindings(lBindings, Item::ONLY_LOCAL_NAMESPACES);
+ for (Item::NsBindings::const_iterator ite = lBindings.begin();
+ ite != lBindings.end(); ++ite) {
+ std::cout << " namespace binding " << ite->first << "->" << ite->second << std::endl;
+ }
}
lChildIter->close();
}
=== modified file 'include/zorba/item.h'
--- include/zorba/item.h 2011-06-14 17:26:33 +0000
+++ include/zorba/item.h 2011-12-31 09:17:24 +0000
@@ -19,6 +19,7 @@
#include <iostream>
#include <zorba/config.h>
#include <zorba/api_shared_types.h>
+#include <vector>
namespace zorba {
@@ -266,7 +267,7 @@
/** \brief Get an iterator for the children of this (node) Item.
*
* Note that this function is only available for node Items.
- * The file \link simple.cpp \endlink contains some basic examples the demonstrate
+ * The file \link simple.cpp \endlink contains some basic examples that demonstrate
* the use of this function.
*
* @return Iterator over the children of this node.
@@ -278,7 +279,7 @@
/** \brief Get an iterator for the attributes of this (node) Item.
*
* Note that this function is only available for node Items.
- * The file \link simple.cpp \endlink contains some basic examples the demonstrate
+ * The file \link simple.cpp \endlink contains some basic examples that demonstrate
* the use of this function.
*
* @return Iterator over the attributes of this node.
@@ -287,6 +288,29 @@
Iterator_t
getAttributes() const;
+ /** \brief Get an iterator for the namespace bindings of this (element) Item.
+ *
+ * Note that this function is only available for element Items.
+ * The file \link simple.cpp \endlink contains some basic examples that demonstrate
+ * the use of this function.
+ *
+ * @param aBindings An STL list to receive the namespace bindings of this node (each
+ * represented as a std::pair<zorba::String,zorba::String> where the
+ * first string is the namespace prefix and the second is the namespace URI).
+ * @param aScope An instance of NsScoping to declare which bindings to return:
+ * those local to the element; those local to all parent elements; or all bindings
+ * (the default).
+ * @throw ZorbaException if an error occured, e.g. the Item is not of type element.
+ */
+ typedef std::vector<std::pair<String, String> > NsBindings;
+ enum NsScoping {
+ ALL_NAMESPACES,
+ ONLY_LOCAL_NAMESPACES,
+ ONLY_PARENT_NAMESPACES
+ };
+ void
+ getNamespaceBindings(NsBindings& aBindings, NsScoping aNsScoping = ALL_NAMESPACES) const;
+
/** \brief Get parent of this (node) Item.
*
* Note that this function is only available for node Items.
@@ -300,7 +324,7 @@
/** \brief Get the name of this (node) Item.
*
* Note that this function is only available for node Items.
- * The file \link simple.cpp \endlink contains some basic examples the demonstrate
+ * The file \link simple.cpp \endlink contains some basic examples that demonstrate
* the use of this function.
*
* @return bool if the name of the node was retrieved successfully
=== modified file 'src/api/item.cpp'
--- src/api/item.cpp 2011-06-14 17:26:33 +0000
+++ src/api/item.cpp 2011-12-31 09:17:24 +0000
@@ -380,6 +380,28 @@
return NULL;
}
+void
+Item::getNamespaceBindings(NsBindings& aBindings, NsScoping aNsScoping) const
+{
+ ITEM_TRY
+ SYNC_CODE(AutoLock lock(GENV_STORE.getGlobalLock(), Lock::READ);)
+
+ store::NsBindings lStoreBindings;
+ // We cheat and just cast the NsScoping enum. Will need to change this
+ // if the API and Store enums get out of sync.
+ m_item->getNamespaceBindings(lStoreBindings,
+ static_cast<store::StoreConsts::NsScoping>(aNsScoping));
+ store::NsBindings::iterator ite = lStoreBindings.begin();
+ store::NsBindings::iterator end = lStoreBindings.end();
+ for (; ite != end; ++ite) {
+ zstring& prefix = ite->first;
+ zstring& nsuri = ite->second;
+ aBindings.push_back(std::pair<String, String>(prefix.str(), nsuri.str()));
+ }
+
+ ITEM_CATCH
+}
+
Item
Item::getParent() const
{
Follow ups
-
[Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: noreply, 2012-01-10
-
[Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Zorba Build Bot, 2012-01-10
-
[Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Zorba Build Bot, 2012-01-10
-
[Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Matthias Brantner, 2012-01-10
-
Re: [Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Matthias Brantner, 2012-01-10
-
[Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Zorba Build Bot, 2012-01-10
-
Re: [Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Zorba Build Bot, 2012-01-10
-
[Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Zorba Build Bot, 2012-01-10
-
[Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Zorba Build Bot, 2012-01-10
-
[Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Chris Hillery, 2012-01-10
-
Re: [Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Chris Hillery, 2012-01-10
-
Re: [Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Matthias Brantner, 2012-01-06
-
[Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Zorba Build Bot, 2012-01-06
-
Re: [Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Zorba Build Bot, 2012-01-06
-
[Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Zorba Build Bot, 2012-01-06
-
[Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Zorba Build Bot, 2012-01-06
-
[Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Chris Hillery, 2012-01-06
-
Re: [Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Chris Hillery, 2012-01-06
-
Re: [Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Chris Hillery, 2012-01-04
-
Re: [Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Matthias Brantner, 2012-01-03
-
[Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Zorba Build Bot, 2011-12-31
-
Re: [Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Zorba Build Bot, 2011-12-31
-
[Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Zorba Build Bot, 2011-12-31
-
[Merge] lp:~zorba-coders/zorba/get-namespace-bindings into lp:zorba
From: Chris Hillery, 2011-12-31