diff --git a/ncclient/operations/util.py b/ncclient/operations/util.py
index b1bd733..0d1bb38 100755
--- a/ncclient/operations/util.py
+++ b/ncclient/operations/util.py
@@ -49,10 +49,12 @@ def build_filter(spec, capcheck=None):
     type = None
     if isinstance(spec, tuple):
         type, criteria = spec
-        rep = new_ele("filter", type=type)
         if type == "xpath":
-            rep.attrib["select"] = criteria
+            ns, select = criteria
+            rep = new_ele_nsmap("filter", ns, type=type)
+            rep.attrib["select"] = select
         elif type == "subtree":
+            rep = new_ele("filter", type=type)
             rep.append(to_ele(criteria))
         else:
             raise OperationError("Invalid filter type")
diff --git a/ncclient/xml_.py b/ncclient/xml_.py
index 8e81c81..adcc742 100644
--- a/ncclient/xml_.py
+++ b/ncclient/xml_.py
@@ -228,6 +228,8 @@ def parent_ns(node):
         return node.nsmap[node.prefix]
     return None
 
+new_ele_nsmap = lambda tag, nsmap, attrs={}, **extra: etree.Element(qualify(tag), attrs, nsmap, **extra)
+
 new_ele = lambda tag, attrs={}, **extra: etree.Element(qualify(tag), attrs, **extra)
 
 new_ele_ns = lambda tag, ns, attrs={}, **extra: etree.Element(qualify(tag,ns), attrs, **extra)

Question: how to pass namespace defintion to xpath filter?
Hi,

I would like to pass an xpath filter to the `get` method. It should be the equivalent of this XML request:

```xml
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="28">
  <get>
    <filter type="subtree">
      <turing-machine xmlns="http://example.net/turing-machine">
        <transition-function />
      </turing-machine>
    </filter>
  </get>
</rpc>
```

I wanted to use something like:
```python
reply = connection.get(filter=("xpath", "/tm:turing-machine/tm:transition-function"))
```

This produces an invalid request, since `tm` namespace is not defined anywhere:
```xml
<nc:rpc xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:6f210162-f037-47ee-93cd-b3034b0100ac">
  <nc:get>
    <nc:filter type="xpath" select="/tm:turing-machine/tm:transition-function"/>
  </nc:get>
</nc:rpc>
```

(Netopeer2 server returns an error: `XML namespace with prefix "tm" not defined.`)

Correct request would look like (this is how `netopeer2-cli` produces it):
```xml
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="30">
  <get>
    <filter type="xpath" xmlns:tm="http://example.net/turing-machine" select="/tm:turing-machine/transition-function"/>
  </get>
</rpc>
```

How this could be achieved with `ncclient`?
diff --git a/test/unit/operations/test_utils.py b/test/unit/operations/test_utils.py
index 7cad8ab..45adbd3 100644
--- a/test/unit/operations/test_utils.py
+++ b/test/unit/operations/test_utils.py
@@ -58,12 +58,14 @@ class TestUtils(unittest.TestCase):
         self.assertEqual(call, ElementTree.tostring(to_ele(xml)))
 
     def test_build_filter_2(self):
-        criteria = "configuration/system"
+        select = "configuration/system"
+        ns = {"ns0": "http://www.xxx.org"}
+        criteria = (ns, select)
         filter = ("xpath", criteria)
         reply = build_filter(filter)
         call = ElementTree.tostring(reply)
-        node = new_ele("filter", type="xpath")
-        node.attrib["select"] = criteria
+        node = new_ele_nsmap("filter", ns, type="xpath")
+        node.attrib["select"] = select
         self.assertEqual(call, ElementTree.tostring(node))
 
     def test_build_filter_3(self):

pip install -e .
parse_log_pytest
requirements.txt
pytest pytest-cov sphinx flake8 mock nose
apt-get update apt-get install -y gcc libxml2-dev libxslt1-dev
3.6
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.13
attrs==22.2.0
Babel==2.11.0
bcrypt==4.0.1
certifi==2021.5.30
cffi==1.15.1
charset-normalizer==2.0.12
coverage==6.2
cryptography==40.0.2
docutils==0.18.1
flake8==3.9.2
idna==3.10
imagesize==1.4.1
importlib-metadata==4.8.3
iniconfig==1.1.1
Jinja2==3.0.3
lxml==5.3.1
MarkupSafe==2.0.1
mccabe==0.6.1
mock==5.2.0
-e git+https://github.com/ncclient/ncclient.git@70d2a3287361d50bce6e867ba6f31b9aa16dc357#egg=ncclient
nose==1.3.7
packaging==21.3
paramiko==3.5.1
pluggy==1.0.0
py==1.11.0
pycodestyle==2.7.0
pycparser==2.21
pyflakes==2.3.1
Pygments==2.14.0
PyNaCl==1.5.0
pyparsing==3.1.4
pytest==7.0.1
pytest-cov==4.0.0
pytz==2025.2
requests==2.27.1
six==1.17.0
snowballstemmer==2.2.0
Sphinx==5.3.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
tomli==1.2.3
typing_extensions==4.1.1
urllib3==1.26.20
zipp==3.6.0

name: ncclient
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.13
      - attrs==22.2.0
      - babel==2.11.0
      - bcrypt==4.0.1
      - cffi==1.15.1
      - charset-normalizer==2.0.12
      - coverage==6.2
      - cryptography==40.0.2
      - docutils==0.18.1
      - flake8==3.9.2
      - idna==3.10
      - imagesize==1.4.1
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - jinja2==3.0.3
      - lxml==5.3.1
      - markupsafe==2.0.1
      - mccabe==0.6.1
      - mock==5.2.0
      - nose==1.3.7
      - packaging==21.3
      - paramiko==3.5.1
      - pluggy==1.0.0
      - py==1.11.0
      - pycodestyle==2.7.0
      - pycparser==2.21
      - pyflakes==2.3.1
      - pygments==2.14.0
      - pynacl==1.5.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - pytest-cov==4.0.0
      - pytz==2025.2
      - requests==2.27.1
      - six==1.17.0
      - snowballstemmer==2.2.0
      - sphinx==5.3.0
      - sphinxcontrib-applehelp==1.0.2
      - sphinxcontrib-devhelp==1.0.2
      - sphinxcontrib-htmlhelp==2.0.0
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==1.0.3
      - sphinxcontrib-serializinghtml==1.1.5
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - zipp==3.6.0
prefix: /opt/conda/envs/ncclient

test/unit/operations/test_utils.py::TestUtils::test_build_filter_2
test/unit/operations/test_utils.py::TestUtils::test_build_filter test/unit/operations/test_utils.py::TestUtils::test_build_filter_3 test/unit/operations/test_utils.py::TestUtils::test_build_filter_4 test/unit/operations/test_utils.py::TestUtils::test_datastore_url test/unit/operations/test_utils.py::TestUtils::test_datastore_url_2 test/unit/operations/test_utils.py::TestUtils::test_datastore_url_3 test/unit/operations/test_utils.py::TestUtils::test_one_of_1 test/unit/operations/test_utils.py::TestUtils::test_one_of_2 test/unit/operations/test_utils.py::TestUtils::test_one_of_3
ncclient/operations/util.py ncclient/xml_.py
ncclient/operations/util.py ncclient/xml_.py