By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,462 Members | 799 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,462 IT Pros & Developers. It's quick & easy.

Testing for non-existing namespace attribute?

P: n/a
Hello!

I'm using msxml3 in the C++ environment, VC 7.1.3088. How do I know if the
namespace attribute doesn't exist? I want to put it in a std::string, and I
try to do that like this:

string CXmlNodeWrapper::GetNamespaceURI() const
{
if( IsValid() )
{
_bstr_t str = m_xmlnode->GetnamespaceURI();
return static_cast<char*>(str); // <- point of exception
}

return "";
}

m_xmlnode is a MSXML2::IXMLDOMNodePtr; This works fine as long as there is
a namespace attribute, but if the root node doesn't have a namespace
attribute this code throws some exception. How do I do this correctly? I
want to return "" if there is no namespace attribute.
Thanks in advance!

--
Daniel
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 24 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Fri, 24 Mar 2006 16:13:17 +0100, Daniel Lidström wrote:
Hello!

I'm using msxml3 in the C++ environment, VC 7.1.3088. How do I know if the
namespace attribute doesn't exist? I want to put it in a std::string, and I
try to do that like this:

string CXmlNodeWrapper::GetNamespaceURI() const
{
if( IsValid() )
{
_bstr_t str = m_xmlnode->GetnamespaceURI();
return static_cast<char*>(str); // <- point of exception
}

return "";
}


I got it:

_bstr_t str = m_xmlnode->GetnamespaceURI();

LPCSTR c_str = (LPCSTR)str;
if( c_str==NULL )
return "";
else
return c_str;
--
Daniel
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 27 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.