.NETGURU
C# and WebDAV
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngxml' list.


Sidney Buss
Hello,

I'm having some problems with WebDav and XML. I couldn't get the
same result
with DOM and Sytem.XML . When I tried with System.XML, I got this
message:
System.Xml.Xsl.XsltException: Prefix 'a' is not defined.
but when I tried with DOM it works.

Here is the code in C#:
string xml = "<?xml version=\"1.0\"?>";
xml += "<a:multistatus
xmlns:b=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\"
xmlns:c=\"xml:\" xmlns:d=\"urn:schemas-microsoft-com:office:office\"
xmlns:a=\"DAV:\"> ";
xml +"<a:response><a:href>http://tatsrvdev00/public/removame/lolopaquito.eml<
/a:href>";
xml += "<a:propstat>";
xml += "<a:status>HTTP/1.1 200 OK</a:status>";
xml += "<a:prop> ";
xml += " <a:contentclass>TEST:MyTest</a:contentclass> ";
xml += " </a:prop>";
xml += " </a:propstat>";
xml += " </a:response></a:multistatus>";

XmlDataDocument xdoc = new XmlDataDocument();

NameTable nt = new NameTable();
String name = nt.Add("//a:contentclass");
//
// Using System.XML
XmlNamespaceManager mngr = new XmlNamespaceManager(nt);
xdoc.LoadXml(xml);

XmlNode nod = xdoc.SelectSingleNode("//a:contentclass", mngr );
Response.Write(nod.ToString());

// With DOM
MSXML2.DOMDocumentClass domDoc = new MSXML2.DOMDocumentClass();
domDoc.loadXML(xml);

MSXML2.IXMLDOMNode xnode = domDoc.selectSingleNode("//a:contentclass");
Response.Write(xnode.text );

Is there other way to do this ?

Thanks,

Sidney
Reply to this message...
 
    
Dan Wahlin
When using the XmlNamespaceManager you need to call the AddNamespace
method if you want to include a local (or default) namespace in an XPath
statement:

ns.AddNamespace("a","DAV");

You'll find an example of using a local and default namespace with
SelectSingleNode() at the following URL:

http://www.xmlforasp.net/codeSection.aspx?csID=7" target="_blank">http://www.xmlforasp.net/codeSection.aspx?csID=7

Also, you'll see much better performance when working with large strings
by using the StringBuilder class located within the System.Text
namespace rather than doing string concatenations. It's really easy to
use and you won't have to change your code much:

StringBuilder sb = new StringBuilder();

sb.Append("<?xml version=\"1.0\"?>");

sb.Append("<a:multistatus
xmlns:b=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\");
sb.Append("xmlns:c=\"xml:\"
xmlns:d=\"urn:schemas-microsoft-com:office:office\" xmlns:a=\"DAV:\">
");

//Continue appending to the StringBuilder

To get the string just call sb.ToString();

HTH,

Dan Wahlin

Wahlin Consulting LLC

Microsoft MVP - ASP.NET

http://www.XMLforASP.Net <http://www.xmlforasp.net/> : #1 ASP.NET XML
Resource

XML
<http://www.amazon.com/exec/obidos/ASIN/0672320398/ref=ase_xmlforaspnetd
-20/104-7101530-2681531> for ASP.NET Developers by Dan Wahlin in
bookstores everywhere!

-----Original Message-----
From: Sidney Buss [mailto:Click here to reveal e-mail address]
Sent: Thursday, July 11, 2002 1:55 PM
To: aspngxml
Subject: [aspngxml] C# and WebDAV

Hello,

I'm having some problems with WebDav and XML. I couldn't get the
same result

with DOM and Sytem.XML . When I tried with System.XML, I got this
message:

System.Xml.Xsl.XsltException: Prefix 'a' is not defined.

but when I tried with DOM it works.

Here is the code in C#:

string xml = "<?xml version=\"1.0\"?>";

xml += "<a:multistatus
xmlns:b=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\"
xmlns:c=\"xml:\" xmlns:d=\"urn:schemas-microsoft-com:office:office\"
xmlns:a=\"DAV:\"> ";

xml +"<a:response><a:href>http://tatsrvdev00/public/removame/lolopaquito.eml<
/a:href>";

xml += "<a:propstat>";

xml += "<a:status>HTTP/1.1 200 OK</a:status>";

xml += "<a:prop> ";

xml += " <a:contentclass>TEST:MyTest</a:contentclass> ";

xml += " </a:prop>";

xml += " </a:propstat>";

xml += " </a:response></a:multistatus>";

XmlDataDocument xdoc = new XmlDataDocument();

NameTable nt = new NameTable();

String name = nt.Add("//a:contentclass");

//

// Using System.XML

XmlNamespaceManager mngr = new XmlNamespaceManager(nt);

xdoc.LoadXml(xml);

XmlNode nod = xdoc.SelectSingleNode("//a:contentclass", mngr );

Response.Write(nod.ToString());

// With DOM

MSXML2.DOMDocumentClass domDoc = new MSXML2.DOMDocumentClass();

domDoc.loadXML(xml);

MSXML2.IXMLDOMNode xnode = domDoc.selectSingleNode("//a:contentclass");

Response.Write(xnode.text );

Is there other way to do this ?

Thanks,

Sidney

| [aspngxml] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngxml.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives
Reply to this message...
 
    
Sidney Buss
Thanks, I have changed and it works OK.

-----Original Message-----
From: Dan Wahlin [mailto:Click here to reveal e-mail address]
Sent: sexta-feira, 12 de julho de 2002 02:16
To: aspngxml
Subject: [aspngxml] RE: C# and WebDAV

When using the XmlNamespaceManager you need to call the AddNamespace
method if you want to include a local (or default) namespace in an XPath
statement:

ns.AddNamespace("a","DAV");

You'll find an example of using a local and default namespace with
SelectSingleNode() at the following URL:

http://www.xmlforasp.net/codeSection.aspx?csID=7" target="_blank">http://www.xmlforasp.net/codeSection.aspx?csID=7

Also, you'll see much better performance when working with large strings
by using the StringBuilder class located within the System.Text
namespace rather than doing string concatenations. It's really easy to
use and you won't have to change your code much:

StringBuilder sb = new StringBuilder();
sb.Append("<?xml version=\"1.0\"?>");
sb.Append("<a:multistatus
xmlns:b=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\");
sb.Append("xmlns:c=\"xml:\"
xmlns:d=\"urn:schemas-microsoft-com:office:office\" xmlns:a=\"DAV:\">
");
//Continue appending to the StringBuilder

To get the string just call sb.ToString();

HTH,
Dan Wahlin

Wahlin Consulting LLC
Microsoft MVP - ASP.NET
http://www.XMLforASP.Net <http://www.xmlforasp.net/> : #1 ASP.NET XML
Resource
XML for ASP.NET Developers
<http://www.amazon.com/exec/obidos/ASIN/0672320398/ref=ase_xmlforaspnetd
-20/104-7101530-2681531> by Dan Wahlin in bookstores everywhere!

-----Original Message-----
From: Sidney Buss [mailto:Click here to reveal e-mail address]
Sent: Thursday, July 11, 2002 1:55 PM
To: aspngxml
Subject: [aspngxml] C# and WebDAV

Hello,

I'm having some problems with WebDav and XML. I couldn't get the
same result
with DOM and Sytem.XML . When I tried with System.XML, I got this
message:
System.Xml.Xsl.XsltException: Prefix 'a' is not defined.
but when I tried with DOM it works.

Here is the code in C#:
string xml = "<?xml version=\"1.0\"?>";
xml += "<a:multistatus
xmlns:b=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\"
xmlns:c=\"xml:\" xmlns:d=\"urn:schemas-microsoft-com:office:office\"
xmlns:a=\"DAV:\"> ";
xml +"<a:response><a:href>http://tatsrvdev00/public/removame/lolopaquito.eml<
/a:href>";
xml += "<a:propstat>";
xml += "<a:status>HTTP/1.1 200 OK</a:status>";
xml += "<a:prop> ";
xml += " <a:contentclass>TEST:MyTest</a:contentclass> ";
xml += " </a:prop>";
xml += " </a:propstat>";
xml += " </a:response></a:multistatus>";

XmlDataDocument xdoc = new XmlDataDocument();

NameTable nt = new NameTable();
String name = nt.Add("//a:contentclass");
//
// Using System.XML
XmlNamespaceManager mngr = new XmlNamespaceManager(nt);
xdoc.LoadXml(xml);

XmlNode nod = xdoc.SelectSingleNode("//a:contentclass", mngr );
Response.Write(nod.ToString());

// With DOM
MSXML2.DOMDocumentClass domDoc = new MSXML2.DOMDocumentClass();
domDoc.loadXML(xml);

MSXML2.IXMLDOMNode xnode = domDoc.selectSingleNode("//a:contentclass");
Response.Write(xnode.text );

Is there other way to do this ?

Thanks,

Sidney
| [aspngxml] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngxml.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives
| [aspngxml] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngxml.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives
Reply to this message...
 
 
System.Text.StringBuilder
System.Xml.NameTable
System.Xml.XmlDataDocument
System.Xml.XmlNamespaceManager
System.Xml.XmlNode
System.Xml.Xsl.XsltException




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification