473,386 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Removing default xmlns from xml

EAI
Hi All,

I have a XML of the following form

<?xml version="1.0"?>
<xxxx xmlns="http://xxx.xxx.com">
....
</xxxx>

When I try to read xml using SelectSingleNode, I am getting exception
"Object reference not set to an instance of an object.". But if I remove
xmlns and change xml into

<?xml version="1.0"?>
<xxxx>
....
</xxxx>

then I am able to read the nodes. Can anyone help me to read nodes with out
altering anything? If thats not possible, how do I remove
xmlns="http://xxx.xxx.com" programmatically.

Thanks!
Nov 17 '05 #1
11 4210
Hi EAI,
you do not want to try to remove the namespace declaration from your xxxx
node, instead try to understand what it is doing and use it to your advantage.

The namspace is declared in the element to indicate that the element and
all subelements belong to a particular namespace, this enables you to have
two elements with the same name i.e <Book> but belonging to different
namespace, and therefore your code should process them differently, if they
didn't belong to different namespaces how would you know which element you
had?

Xml namespaces are exactly the same principle as namespaces in .Net. If
you have two types called MyObject in different projects how can you tell
them apart in your code, you add them to different namespaces i.e.

namespace ns1
{
public class MyObject.......
}

namespace ns2
{
public class MyObject......
}

In your example you need to tell XPath what is the namespace associated with
the node, if you do not do this it will not be able to find it in your query.
For example, if we have XML like:
<MyBooks>
<Book xmlns="http://www.foo.com">The Book</Book>
</MyBooks>

In order to select the Book element which belongs to the http://www.foo.com
default namespace you have to do the following in your code:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"c:\test123.xml"); -> this contains the above xml

//create a namespace manager for the document
XmlNamespaceManager nsm = new XmlNamespaceManager(xmlDoc.NameTable);

//add your namespace and give it some arbitrary name i.e. b
//this is the name you will use in your x path to equate to http://www.foo.com
nsm.AddNamespace("b", "http://www.foo.com");

//now in your xpath you need to use the 'b' to reference the namespaced node
XmlNode nd = xmlDoc.SelectSingleNode("/MyBooks/b:Book", nsm);
Hope that helps point you in the right direction.
Mark R Dawson

"EAI" wrote:
Hi All,

I have a XML of the following form

<?xml version="1.0"?>
<xxxx xmlns="http://xxx.xxx.com">
....
</xxxx>

When I try to read xml using SelectSingleNode, I am getting exception
"Object reference not set to an instance of an object.". But if I remove
xmlns and change xml into

<?xml version="1.0"?>
<xxxx>
....
</xxxx>

then I am able to read the nodes. Can anyone help me to read nodes with out
altering anything? If thats not possible, how do I remove
xmlns="http://xxx.xxx.com" programmatically.

Thanks!

Nov 17 '05 #2
Hi EAI,
you do not want to try to remove the namespace declaration from your xxxx
node, instead try to understand what it is doing and use it to your advantage.

The namspace is declared in the element to indicate that the element and
all subelements belong to a particular namespace, this enables you to have
two elements with the same name i.e <Book> but belonging to different
namespace, and therefore your code should process them differently, if they
didn't belong to different namespaces how would you know which element you
had?

Xml namespaces are exactly the same principle as namespaces in .Net. If
you have two types called MyObject in different projects how can you tell
them apart in your code, you add them to different namespaces i.e.

namespace ns1
{
public class MyObject.......
}

namespace ns2
{
public class MyObject......
}

In your example you need to tell XPath what is the namespace associated with
the node, if you do not do this it will not be able to find it in your query.
For example, if we have XML like:
<MyBooks>
<Book xmlns="http://www.foo.com">The Book</Book>
</MyBooks>

In order to select the Book element which belongs to the http://www.foo.com
default namespace you have to do the following in your code:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"c:\test123.xml"); -> this contains the above xml

//create a namespace manager for the document
XmlNamespaceManager nsm = new XmlNamespaceManager(xmlDoc.NameTable);

//add your namespace and give it some arbitrary name i.e. b
//this is the name you will use in your x path to equate to http://www.foo.com
nsm.AddNamespace("b", "http://www.foo.com");

//now in your xpath you need to use the 'b' to reference the namespaced node
XmlNode nd = xmlDoc.SelectSingleNode("/MyBooks/b:Book", nsm);
Hope that helps point you in the right direction.
Mark R Dawson

"EAI" wrote:
Hi All,

I have a XML of the following form

<?xml version="1.0"?>
<xxxx xmlns="http://xxx.xxx.com">
....
</xxxx>

When I try to read xml using SelectSingleNode, I am getting exception
"Object reference not set to an instance of an object.". But if I remove
xmlns and change xml into

<?xml version="1.0"?>
<xxxx>
....
</xxxx>

then I am able to read the nodes. Can anyone help me to read nodes with out
altering anything? If thats not possible, how do I remove
xmlns="http://xxx.xxx.com" programmatically.

Thanks!

Nov 17 '05 #3
EAI
Mark,

Thanks for your reply. I understand the significance of namespaces. But my
case is different.

Thanks!

"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...
Hi EAI,
you do not want to try to remove the namespace declaration from your xxxx
node, instead try to understand what it is doing and use it to your
advantage.

The namspace is declared in the element to indicate that the element and
all subelements belong to a particular namespace, this enables you to have
two elements with the same name i.e <Book> but belonging to different
namespace, and therefore your code should process them differently, if
they
didn't belong to different namespaces how would you know which element you
had?

Xml namespaces are exactly the same principle as namespaces in .Net. If
you have two types called MyObject in different projects how can you tell
them apart in your code, you add them to different namespaces i.e.

namespace ns1
{
public class MyObject.......
}

namespace ns2
{
public class MyObject......
}

In your example you need to tell XPath what is the namespace associated
with
the node, if you do not do this it will not be able to find it in your
query.
For example, if we have XML like:
<MyBooks>
<Book xmlns="http://www.foo.com">The Book</Book>
</MyBooks>

In order to select the Book element which belongs to the
http://www.foo.com
default namespace you have to do the following in your code:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"c:\test123.xml"); -> this contains the above xml

//create a namespace manager for the document
XmlNamespaceManager nsm = new XmlNamespaceManager(xmlDoc.NameTable);

//add your namespace and give it some arbitrary name i.e. b
//this is the name you will use in your x path to equate to
http://www.foo.com
nsm.AddNamespace("b", "http://www.foo.com");

//now in your xpath you need to use the 'b' to reference the namespaced
node
XmlNode nd = xmlDoc.SelectSingleNode("/MyBooks/b:Book", nsm);
Hope that helps point you in the right direction.
Mark R Dawson

"EAI" wrote:
Hi All,

I have a XML of the following form

<?xml version="1.0"?>
<xxxx xmlns="http://xxx.xxx.com">
....
</xxxx>

When I try to read xml using SelectSingleNode, I am getting exception
"Object reference not set to an instance of an object.". But if I remove
xmlns and change xml into

<?xml version="1.0"?>
<xxxx>
....
</xxxx>

then I am able to read the nodes. Can anyone help me to read nodes with
out
altering anything? If thats not possible, how do I remove
xmlns="http://xxx.xxx.com" programmatically.

Thanks!

Nov 17 '05 #4
EAI
Mark,

Thanks for your reply. I understand the significance of namespaces. But my
case is different.

Thanks!

"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...
Hi EAI,
you do not want to try to remove the namespace declaration from your xxxx
node, instead try to understand what it is doing and use it to your
advantage.

The namspace is declared in the element to indicate that the element and
all subelements belong to a particular namespace, this enables you to have
two elements with the same name i.e <Book> but belonging to different
namespace, and therefore your code should process them differently, if
they
didn't belong to different namespaces how would you know which element you
had?

Xml namespaces are exactly the same principle as namespaces in .Net. If
you have two types called MyObject in different projects how can you tell
them apart in your code, you add them to different namespaces i.e.

namespace ns1
{
public class MyObject.......
}

namespace ns2
{
public class MyObject......
}

In your example you need to tell XPath what is the namespace associated
with
the node, if you do not do this it will not be able to find it in your
query.
For example, if we have XML like:
<MyBooks>
<Book xmlns="http://www.foo.com">The Book</Book>
</MyBooks>

In order to select the Book element which belongs to the
http://www.foo.com
default namespace you have to do the following in your code:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"c:\test123.xml"); -> this contains the above xml

//create a namespace manager for the document
XmlNamespaceManager nsm = new XmlNamespaceManager(xmlDoc.NameTable);

//add your namespace and give it some arbitrary name i.e. b
//this is the name you will use in your x path to equate to
http://www.foo.com
nsm.AddNamespace("b", "http://www.foo.com");

//now in your xpath you need to use the 'b' to reference the namespaced
node
XmlNode nd = xmlDoc.SelectSingleNode("/MyBooks/b:Book", nsm);
Hope that helps point you in the right direction.
Mark R Dawson

"EAI" wrote:
Hi All,

I have a XML of the following form

<?xml version="1.0"?>
<xxxx xmlns="http://xxx.xxx.com">
....
</xxxx>

When I try to read xml using SelectSingleNode, I am getting exception
"Object reference not set to an instance of an object.". But if I remove
xmlns and change xml into

<?xml version="1.0"?>
<xxxx>
....
</xxxx>

then I am able to read the nodes. Can anyone help me to read nodes with
out
altering anything? If thats not possible, how do I remove
xmlns="http://xxx.xxx.com" programmatically.

Thanks!

Nov 17 '05 #5
Hi EAI,
I suspect if you are getting a "Object not set to instance of an object"
exception using SelectSingleNode you might be trying to access the properties
of a node that is null because the XPath search is wrong.

For example:

XmlNode nd = xmlDoc.SelectSingleNode("some wrong x path");

//nd is null at this point.
string strName = nd.Attributes["name"].Value

I may be wrong, a copy of your code would hlep to see what is going wrong.
I can use select single node without any problem, by adding the default
namespace to the XmlDocuments namespace table, like in the example below, is
your code like this?

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml("<Root
xmlns=\"http://www.foo.com\"><somenode></somenode></Root>");

XmlNamespaceManager nsm = new XmlNamespaceManager(xmlDoc.NameTable);
nsm.AddNamespace("b", "http://www.foo.com");
XmlNode nd = xmlDoc.SelectSingleNode("/b:Root/b:somenode", nsm);

Hope that helps
Mark R Dawson

"EAI" wrote:
Mark,

Thanks for your reply. I understand the significance of namespaces. But my
case is different.

Thanks!

"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...
Hi EAI,
you do not want to try to remove the namespace declaration from your xxxx
node, instead try to understand what it is doing and use it to your
advantage.

The namspace is declared in the element to indicate that the element and
all subelements belong to a particular namespace, this enables you to have
two elements with the same name i.e <Book> but belonging to different
namespace, and therefore your code should process them differently, if
they
didn't belong to different namespaces how would you know which element you
had?

Xml namespaces are exactly the same principle as namespaces in .Net. If
you have two types called MyObject in different projects how can you tell
them apart in your code, you add them to different namespaces i.e.

namespace ns1
{
public class MyObject.......
}

namespace ns2
{
public class MyObject......
}

In your example you need to tell XPath what is the namespace associated
with
the node, if you do not do this it will not be able to find it in your
query.
For example, if we have XML like:
<MyBooks>
<Book xmlns="http://www.foo.com">The Book</Book>
</MyBooks>

In order to select the Book element which belongs to the
http://www.foo.com
default namespace you have to do the following in your code:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"c:\test123.xml"); -> this contains the above xml

//create a namespace manager for the document
XmlNamespaceManager nsm = new XmlNamespaceManager(xmlDoc.NameTable);

//add your namespace and give it some arbitrary name i.e. b
//this is the name you will use in your x path to equate to
http://www.foo.com
nsm.AddNamespace("b", "http://www.foo.com");

//now in your xpath you need to use the 'b' to reference the namespaced
node
XmlNode nd = xmlDoc.SelectSingleNode("/MyBooks/b:Book", nsm);
Hope that helps point you in the right direction.
Mark R Dawson

"EAI" wrote:
Hi All,

I have a XML of the following form

<?xml version="1.0"?>
<xxxx xmlns="http://xxx.xxx.com">
....
</xxxx>

When I try to read xml using SelectSingleNode, I am getting exception
"Object reference not set to an instance of an object.". But if I remove
xmlns and change xml into

<?xml version="1.0"?>
<xxxx>
....
</xxxx>

then I am able to read the nodes. Can anyone help me to read nodes with
out
altering anything? If thats not possible, how do I remove
xmlns="http://xxx.xxx.com" programmatically.

Thanks!


Nov 17 '05 #6
Hi EAI,
I suspect if you are getting a "Object not set to instance of an object"
exception using SelectSingleNode you might be trying to access the properties
of a node that is null because the XPath search is wrong.

For example:

XmlNode nd = xmlDoc.SelectSingleNode("some wrong x path");

//nd is null at this point.
string strName = nd.Attributes["name"].Value

I may be wrong, a copy of your code would hlep to see what is going wrong.
I can use select single node without any problem, by adding the default
namespace to the XmlDocuments namespace table, like in the example below, is
your code like this?

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml("<Root
xmlns=\"http://www.foo.com\"><somenode></somenode></Root>");

XmlNamespaceManager nsm = new XmlNamespaceManager(xmlDoc.NameTable);
nsm.AddNamespace("b", "http://www.foo.com");
XmlNode nd = xmlDoc.SelectSingleNode("/b:Root/b:somenode", nsm);

Hope that helps
Mark R Dawson

"EAI" wrote:
Mark,

Thanks for your reply. I understand the significance of namespaces. But my
case is different.

Thanks!

"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...
Hi EAI,
you do not want to try to remove the namespace declaration from your xxxx
node, instead try to understand what it is doing and use it to your
advantage.

The namspace is declared in the element to indicate that the element and
all subelements belong to a particular namespace, this enables you to have
two elements with the same name i.e <Book> but belonging to different
namespace, and therefore your code should process them differently, if
they
didn't belong to different namespaces how would you know which element you
had?

Xml namespaces are exactly the same principle as namespaces in .Net. If
you have two types called MyObject in different projects how can you tell
them apart in your code, you add them to different namespaces i.e.

namespace ns1
{
public class MyObject.......
}

namespace ns2
{
public class MyObject......
}

In your example you need to tell XPath what is the namespace associated
with
the node, if you do not do this it will not be able to find it in your
query.
For example, if we have XML like:
<MyBooks>
<Book xmlns="http://www.foo.com">The Book</Book>
</MyBooks>

In order to select the Book element which belongs to the
http://www.foo.com
default namespace you have to do the following in your code:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"c:\test123.xml"); -> this contains the above xml

//create a namespace manager for the document
XmlNamespaceManager nsm = new XmlNamespaceManager(xmlDoc.NameTable);

//add your namespace and give it some arbitrary name i.e. b
//this is the name you will use in your x path to equate to
http://www.foo.com
nsm.AddNamespace("b", "http://www.foo.com");

//now in your xpath you need to use the 'b' to reference the namespaced
node
XmlNode nd = xmlDoc.SelectSingleNode("/MyBooks/b:Book", nsm);
Hope that helps point you in the right direction.
Mark R Dawson

"EAI" wrote:
Hi All,

I have a XML of the following form

<?xml version="1.0"?>
<xxxx xmlns="http://xxx.xxx.com">
....
</xxxx>

When I try to read xml using SelectSingleNode, I am getting exception
"Object reference not set to an instance of an object.". But if I remove
xmlns and change xml into

<?xml version="1.0"?>
<xxxx>
....
</xxxx>

then I am able to read the nodes. Can anyone help me to read nodes with
out
altering anything? If thats not possible, how do I remove
xmlns="http://xxx.xxx.com" programmatically.

Thanks!


Nov 17 '05 #7
EAI
Mark,

Thanks for reply. Here is a small part of what I have

<?xml version="1.0"?>
<X12_4010_837
xmlns="http://schemas.wpc-edi.com/X12/ISOMORPH/HIPAA/4010A1/TS837Q1">
<X12_EnvelopeHeader>
......
</X12_EnvelopeHeader>

<!-- Other Nodes -->

</X12_4010_837>

The above throws an exception...

<?xml version="1.0"?>
<X12_4010_837>
<X12_EnvelopeHeader>
......
</X12_EnvelopeHeader>

<!-- Other Nodes -->

</X12_4010_837>

The above doesn't. So i want to remove
xmlns="http://schemas.wpc-edi.com/X12/ISOMORPH/HIPAA/4010A1/TS837Q1" from
the XMLDocument.

Thanks!

"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:71**********************************@microsof t.com...
Hi EAI,
I suspect if you are getting a "Object not set to instance of an object"
exception using SelectSingleNode you might be trying to access the
properties
of a node that is null because the XPath search is wrong.

For example:

XmlNode nd = xmlDoc.SelectSingleNode("some wrong x path");

//nd is null at this point.
string strName = nd.Attributes["name"].Value

I may be wrong, a copy of your code would hlep to see what is going wrong.
I can use select single node without any problem, by adding the default
namespace to the XmlDocuments namespace table, like in the example below,
is
your code like this?

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml("<Root
xmlns=\"http://www.foo.com\"><somenode></somenode></Root>");

XmlNamespaceManager nsm = new XmlNamespaceManager(xmlDoc.NameTable);
nsm.AddNamespace("b", "http://www.foo.com");
XmlNode nd = xmlDoc.SelectSingleNode("/b:Root/b:somenode", nsm);

Hope that helps
Mark R Dawson

"EAI" wrote:
Mark,

Thanks for your reply. I understand the significance of namespaces. But
my
case is different.

Thanks!

"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...
> Hi EAI,
> you do not want to try to remove the namespace declaration from your
> xxxx
> node, instead try to understand what it is doing and use it to your
> advantage.
>
> The namspace is declared in the element to indicate that the element
> and
> all subelements belong to a particular namespace, this enables you to
> have
> two elements with the same name i.e <Book> but belonging to different
> namespace, and therefore your code should process them differently, if
> they
> didn't belong to different namespaces how would you know which element
> you
> had?
>
> Xml namespaces are exactly the same principle as namespaces in .Net.
> If
> you have two types called MyObject in different projects how can you
> tell
> them apart in your code, you add them to different namespaces i.e.
>
> namespace ns1
> {
> public class MyObject.......
> }
>
> namespace ns2
> {
> public class MyObject......
> }
>
> In your example you need to tell XPath what is the namespace associated
> with
> the node, if you do not do this it will not be able to find it in your
> query.
> For example, if we have XML like:
>
>
> <MyBooks>
> <Book xmlns="http://www.foo.com">The Book</Book>
> </MyBooks>
>
> In order to select the Book element which belongs to the
> http://www.foo.com
> default namespace you have to do the following in your code:
>
>
> XmlDocument xmlDoc = new XmlDocument();
> xmlDoc.Load(@"c:\test123.xml"); -> this contains the above xml
>
> //create a namespace manager for the document
> XmlNamespaceManager nsm = new XmlNamespaceManager(xmlDoc.NameTable);
>
> //add your namespace and give it some arbitrary name i.e. b
> //this is the name you will use in your x path to equate to
> http://www.foo.com
> nsm.AddNamespace("b", "http://www.foo.com");
>
> //now in your xpath you need to use the 'b' to reference the namespaced
> node
> XmlNode nd = xmlDoc.SelectSingleNode("/MyBooks/b:Book", nsm);
>
>
> Hope that helps point you in the right direction.
> Mark R Dawson
>
> "EAI" wrote:
>
>> Hi All,
>>
>> I have a XML of the following form
>>
>> <?xml version="1.0"?>
>> <xxxx xmlns="http://xxx.xxx.com">
>> ....
>> </xxxx>
>>
>> When I try to read xml using SelectSingleNode, I am getting exception
>> "Object reference not set to an instance of an object.". But if I
>> remove
>> xmlns and change xml into
>>
>> <?xml version="1.0"?>
>> <xxxx>
>> ....
>> </xxxx>
>>
>> then I am able to read the nodes. Can anyone help me to read nodes
>> with
>> out
>> altering anything? If thats not possible, how do I remove
>> xmlns="http://xxx.xxx.com" programmatically.
>>
>> Thanks!
>>
>>
>>


Nov 17 '05 #8
EAI wrote:

<snip>
The above doesn't. So i want to remove
xmlns="http://schemas.wpc-edi.com/X12/ISOMORPH/HIPAA/4010A1/TS837Q1" from
the XMLDocument.


Following this discussion, I get the impression there's some
misunderstanding here. Mark is suggesting, I believe, that you try a
different approach to the issue, because there's really no reason at all
to remove the xmlns attribute from your document. I've done this a lot
myself and I think that Mark's suggestion should work fine for you. Have
you tried it with the sample code he gave?

A few messages back you stated that your situation is different. I'm
willing to believe that, but I'd like to know how it's different, so I
may be able to make a different suggestion.

PMFJI, anyway.
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Nov 17 '05 #9
EAI
Oliver,

Thanks for reply. Here is what i tried. I still get the same error message

XmlNamespaceManager nsm = new XmlNamespaceManager(xmlD.NameTable);
nsm.AddNamespace("b",
"http://schemas.wpc-edi.com/X12/ISOMORPH/HIPAA/4010A1/TS837Q1");

Used 'nsm' in Select single Node..

It did not work. In this case, I have a XMLDocument. I just want to read
nodes from that xml document. If I delete
'xmlns="http://schemas.wpc-edi.com/X12/ISOMORPH/HIPAA/4010A1/TS837Q1"' from
XML, it works fine. For this problem I have two possible solutions. One
deleting the above from XmlDocument. The next being able to read with out
modifying XmlDocument. I followed the way Mark suggested. Since it did not
work I am using a work around solution of using XSLT to eliminate "xmlns".

Thanks!
"Oliver Sturm" <ol****@sturmnet.org> wrote in message
news:um**************@TK2MSFTNGP12.phx.gbl...
EAI wrote:

<snip>
The above doesn't. So i want to remove
xmlns="http://schemas.wpc-edi.com/X12/ISOMORPH/HIPAA/4010A1/TS837Q1" from
the XMLDocument.


Following this discussion, I get the impression there's some
misunderstanding here. Mark is suggesting, I believe, that you try a
different approach to the issue, because there's really no reason at all
to remove the xmlns attribute from your document. I've done this a lot
myself and I think that Mark's suggestion should work fine for you. Have
you tried it with the sample code he gave?

A few messages back you stated that your situation is different. I'm
willing to believe that, but I'd like to know how it's different, so I may
be able to make a different suggestion.

PMFJI, anyway.
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog

Nov 17 '05 #10
EAI wrote:
Thanks for reply. Here is what i tried. I still get the same error message

XmlNamespaceManager nsm = new XmlNamespaceManager(xmlD.NameTable);
nsm.AddNamespace("b",
"http://schemas.wpc-edi.com/X12/ISOMORPH/HIPAA/4010A1/TS837Q1");

Used 'nsm' in Select single Node..


Can you show a code sample of how you called SelectSingleNode?

Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Nov 17 '05 #11
Hi EAI,
I am running out of ideas :-) I ran the code below and it seems to work
for me, something else must be different on your end.
XmlDocument xmlDoc;

xmlDoc = new XmlDocument();
xmlDoc.LoadXml("<X12_4010_83
xmlns=\"http://schemas.wpc-edi.com/X12/ISOMORPH/HIPAA/4010A1/TS837Q1\"><X12_EnvelopeHeader></X12_EnvelopeHeader></X12_4010_837>");

XmlNamespaceManager nsm = new XmlNamespaceManager(xmlDoc.NameTable);
nsm.AddNamespace("b",
"http://schemas.wpc-edi.com/X12/ISOMORPH/HIPAA/4010A1/TS837Q1");

XmlNode nd1 = xmlDoc.SelectSingleNode("b:X12_4010_837", nsm);
XmlNode nd2 =
xmlDoc.SelectSingleNode("b:X12_4010_837/b:X12_EnvelopeHeader", nsm);
Mark R Dawson

"EAI" wrote:
Oliver,

Thanks for reply. Here is what i tried. I still get the same error message

XmlNamespaceManager nsm = new XmlNamespaceManager(xmlD.NameTable);
nsm.AddNamespace("b",
"http://schemas.wpc-edi.com/X12/ISOMORPH/HIPAA/4010A1/TS837Q1");

Used 'nsm' in Select single Node..

It did not work. In this case, I have a XMLDocument. I just want to read
nodes from that xml document. If I delete
'xmlns="http://schemas.wpc-edi.com/X12/ISOMORPH/HIPAA/4010A1/TS837Q1"' from
XML, it works fine. For this problem I have two possible solutions. One
deleting the above from XmlDocument. The next being able to read with out
modifying XmlDocument. I followed the way Mark suggested. Since it did not
work I am using a work around solution of using XSLT to eliminate "xmlns".

Thanks!
"Oliver Sturm" <ol****@sturmnet.org> wrote in message
news:um**************@TK2MSFTNGP12.phx.gbl...
EAI wrote:

<snip>
The above doesn't. So i want to remove
xmlns="http://schemas.wpc-edi.com/X12/ISOMORPH/HIPAA/4010A1/TS837Q1" from
the XMLDocument.


Following this discussion, I get the impression there's some
misunderstanding here. Mark is suggesting, I believe, that you try a
different approach to the issue, because there's really no reason at all
to remove the xmlns attribute from your document. I've done this a lot
myself and I think that Mark's suggestion should work fine for you. Have
you tried it with the sample code he gave?

A few messages back you stated that your situation is different. I'm
willing to believe that, but I'd like to know how it's different, so I may
be able to make a different suggestion.

PMFJI, anyway.
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog


Nov 17 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Keith Hill | last post by:
I am creating an XmlDocument in code and then using XmlTextWriter via doc.WriteTo(xwriter) to output the result to a text box. I have a root element that defines a default namespace. However, the...
1
by: Jack Colletta | last post by:
Hello, If I have a xml document with a rootlevel <workOrderReleased xmlns="http://www.qad.com/qdoc" xmlns:enc="http://www.w3.org/2002/12/soap-encoding"...
2
by: Manoj G | last post by:
Hello, I believe there is no way to remove the default namespace declaration (For eg <DataSet xmlns="something">.... ) on an XmlNode object directly through DOM. So, what is the best way to...
0
by: EAI | last post by:
Hi All, I have a XML of the following form <?xml version="1.0"?> <xxxx xmlns="http://xxx.xxx.com"> .... </xxxx> When I try to read xml using SelectSingleNode, I am getting exception
7
by: Simon Hart | last post by:
Hi, I have a requirement to remove the xmlns from the DOM in order to pass over to MS CRM 3.0 Fetch method.It seems the fetch method blows up if there is a xmlns present!?! The reason I have a...
6
by: Chris Chiasson | last post by:
Hi, After reading and experimenting for a several hours, I have this stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"...
3
by: Keith Patrick | last post by:
I'm doing some document merging where I want to bring in an XmlDocument and import its document element into another document deeper in its tree. However, when serializing my underlying objects,...
0
by: nappingcub | last post by:
This is my first time coding a web service in .NET and ran into a slight snag that I was hoping that anyone could help me out on. I'm using the generic Hello World web service that is stubbed out on...
6
by: Olagato | last post by:
I need to transform this: <urlset xmlns="http://www.google.com/schemas/sitemap/0.84"> <url> <loc>http://localhost/index.php/index./Paths-for-the-extreme-player</ loc> </url> <url>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.