Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7061149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:26:20+00:00 2026-05-28T04:26:20+00:00

I am writing a custom WebDAV server in C#. One of the client test

  • 0

I am writing a custom WebDAV server in C#. One of the client test programs I am using is NetDrive and it claims and appears to be a WebDAV compliant client. My problem is I am receiving a request on the server in the following format:

<?xml version="1.0" encoding="utf-8"?>
<propfind xmlns="DAV:">
    <allprop/>
</propfind>

But other clients do this:

<?xml version="1.0" encoding="utf-8"?>
<D:propfind xmlns:D="DAV:">
    <D:allprop/>
</D:propfind>

The two different namespace formats keep on fooing up my logic to look for the “allprop” element. My code looks a bit like this:

string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><propfind xmlns=\"DAV:\"><allprop/></propfind>"; //Hardcode to make all the StackOverflow users' lives easier
XPathDocument doc = new XPathDocument(new StringReader(xml));
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator it = nav.Select("/propfind/*");

Now, I know I need to put in some type of namespace manager for the “DAV:”, so I tried this:

XmlNamespaceManager nsman = new XmlNamespaceManager(nav.NameTable);
nsman.AddNamespace("", "DAV");
XPathNodeIterator it = nav.Select("/propfind/*", nsman);

But I’m getting no nodes in my iterator for the first XML file. It seems the default namespace isn’t working like I thought it should.

What am I doing wrong? How do I query this XML for the existence of an allprop node when the namespace may be the default, or may be explicitly named?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:26:20+00:00Added an answer on May 28, 2026 at 4:26 am

    I ended up looking for the namespace URI (DAV:) and adding it if it didn’t exist. Then I just did a namespace-qualified SELECT and it worked in all my test cases:

    XPathDocument document = new XPathDocument(xml);
    XPathNavigator navigator = document.CreateNavigator();
    
    //Get namespaces & add them to the search
    bool hasDAV = false;
    string davPrefix = "D";
    XmlNamespaceManager nsman = new XmlNamespaceManager(navigator.NameTable);
    
    foreach (KeyValuePair<string, string> nskvp in navigator.GetNamespacesInScope(XmlNamespaceScope.All))
    {
        if (string.Compare(nskvp.Value, "DAV:", StringComparison.InvariantCultureIgnoreCase) == 0)
        {
            hasDAV = true;
            davPrefix = nskvp.Key;
        }
        nsman.AddNamespace(nskvp.Key, nskvp.Value);
    }
    
    if (!hasDAV)
        nsman.AddNamespace(davPrefix , "DAV:");
    
    
    XPathNodeIterator iterator = navigator.Select("/" + davPrefix + ":" + WebDavXML.PropFind + "/*", nsman);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Overview of the problem: I've been playing with writing custom http server apps for
When writing a custom server, what are the best practices or techniques to determine
I'm writing a custom validator that checks that at least one field has a
I'm writing custom security attribute and got strange compiler behaviour... When I'm using the
It seems most apps are writing custom logic to sync/replicate cloud data, or using
I'm new to writing custom ASP.NET server controls, and I'm encountering the following issue:
I am using NSPasteboardWriting protocol for writing custom object on NSPasteboard. How to create
I'm writing a custom WebDav integration for our website and in IE I can
When it comes to writing custom MySQL database-driven PHP session management for a VERY
while writing a custom attribute in C# i was wondering if there are any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.