473,799 Members | 3,017 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add XmlNode

Here I have the definition of an XmlNode which is a property (PayPreference)
on my Customer class containing an enum describing how the customer will
pay.

<PayPerferenc e xsi:type="a4:Cu stomer+Customer PayOptions"
xmlns:a4="http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage/OsfDomain%2C%20 Version%3D1.0.0 .1%2C%20Culture %3Dneutral%2C%2 0PublicKeyToken %3Dnull">cash</PayPerference>

I now want to add this XmlNode to a different Xml file where the Customer
class has not defined a PayPreference property. I get as far as locating
the parent XmlNode (Customer). Now I just need to add the XmlNode defined
above. To do this, I understand that I need to ask the XmlDocument to
create the node first before I ask the Customer node to 'AppendChild'. I
notice 3 overloads of CreateElement on the XmlDocument to do this:

CreateElement(s tring name)
CreateElement(s tring qualifiedName, string namespaceURI)
CreateElement(s tring prefix, string localName, string namespaceURI)

So now I'm stuck as to what I need to do now. Any help would be
appreciated!


Nov 12 '05 #1
5 5100
Hi Paul,

Welcome to MSDN newsgroup.
Regarding the adding XmlNode into XmlDocument question you mentioned, we
can just use the XmlDocument.Cre ateElement to create a Element xml node and
then locate the parent node where we want to append the new element. Then,
we can use the XmlElement(XmlN ode) 's AppendChild method to add the new
element. Also, in your scenario, your element has some additional
namespace declaration attributes, we need to append them into the new
element or in the document also. here is a simple example on creating a new
xmlelement and add into a existing xmldoument:

the original document is like:

=============== ==
<?xml version="1.0" encoding="utf-8" ?>
<root xmlns="http://www.mytest.org" >
<datas>
<data id="1">
<item>fsfdsfs </item>
</data>
<data id="2">
<item>fksfjkdsj fdks</item>
</data>
</datas>
</root>
=============== ====

the code that modify the document is:
=============== =====
static void RunXmlDoc()
{
XmlDocument doc = new XmlDocument();
doc.Load(@"..\. .\testxml.xml") ;

XmlElement elm = doc.CreateEleme nt("PayPerferen ce");

elm.InnerText = "cash";
XmlAttribute nsattr = null;

nsattr =
doc.CreateAttri bute("xmlns","x si","http://www.w3.org/2000/xmlns/");
nsattr.InnerTex t = "http://www.w3.org/2001/XMLSchema-instance";

elm.Attributes. Append(
nsattr
);

//
nsattr =
doc.CreateAttri bute("xmlns","a 4","http://www.w3.org/2000/xmlns/");
nsattr.InnerTex t =
"http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage/OsfDomai
n%2C%20Version% 3D1.0.0.1%2C%20 Culture%3Dneutr al%2C%20PublicK eyToken%3Dnull" ;

elm.Attributes. Append(
nsattr
);
nsattr =
doc.CreateAttri bute("xsi","typ e","http://www.w3.org/2001/XMLSchema-instance"
);
nsattr.InnerTex t = "a4:Customer+Cu stomerPayOption s";
elm.Attributes. Append(
nsattr
);

XmlNamespaceMan ager manager = new XmlNamespaceMan ager(doc.NameTa ble);
manager.AddName space("ns1","ht tp://www.mytest.org" );

XmlElement datas = doc.SelectSingl eNode("/ns1:root/ns1:datas",mana ger)
as XmlElement;

datas.AppendChi ld(elm);

Console.WriteLi ne(doc.OuterXml );

doc.Save("outpu t.xml");

}
=============== ============

The output.xml will be something like;

=============== =========
<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://www.mytest.org" >
<datas>
<data id="1">
<item>fsfdsfs </item>
</data>
<data id="2">
<item>fksfjkdsj fdks</item>
</data>
<PayPerferenc e xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xmlns:a4="http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage
/OsfDomain%2C%20 Version%3D1.0.0 .1%2C%20Culture %3Dneutral%2C%2 0PublicKeyToken
%3Dnull" xsi:type="a4:Cu stomer+Customer PayOptions"
xmlns="">cash</PayPerference>
</datas>
</root>
=============== =============

Also, you can find the the "PayPerfere nce" element in the output has an
empty default namespace

xmlns=""

you can explicitly specify the default namespace by changing the
XmlElement's construction to below:

XmlElement elm =
doc.CreateEleme nt("PayPerferen ce","http://www.mycustomapp .com");

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Paul" <pa*****@commun ity.nospam>
| Subject: Add XmlNode
| Date: Wed, 26 Oct 2005 11:29:29 -0700
| Lines: 28
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <uh************ *@TK2MSFTNGP15. phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.xml
| NNTP-Posting-Host: 66.236.123.34.p tr.us.xo.net 66.236.123.34
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP15.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl microsoft.publi c.dotnet.xml:90 85
| X-Tomcat-NG: microsoft.publi c.dotnet.xml
|
| Here I have the definition of an XmlNode which is a property
(PayPreference)
| on my Customer class containing an enum describing how the customer will
| pay.
|
| <PayPerferenc e xsi:type="a4:Cu stomer+Customer PayOptions"
|
xmlns:a4="http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage
/OsfDomain%2C%20 Version%3D1.0.0 .1%2C%20Culture %3Dneutral%2C%2 0PublicKeyToken
%3Dnull">cash</PayPerference>
|
| I now want to add this XmlNode to a different Xml file where the Customer
| class has not defined a PayPreference property. I get as far as locating
| the parent XmlNode (Customer). Now I just need to add the XmlNode
defined
| above. To do this, I understand that I need to ask the XmlDocument to
| create the node first before I ask the Customer node to 'AppendChild'. I
| notice 3 overloads of CreateElement on the XmlDocument to do this:
|
| CreateElement(s tring name)
| CreateElement(s tring qualifiedName, string namespaceURI)
| CreateElement(s tring prefix, string localName, string namespaceURI)
|
| So now I'm stuck as to what I need to do now. Any help would be
| appreciated!
|
|
|
|
|
|
|
|
|

Nov 12 '05 #2
Hello Steven and thank you for your reply!!

Your solution worked well and it seems that
the part I was missing was that I needed to ask
the document to create the new XmlAttribute and not
the newly created node.

I do have a followup question. In your solution you hard-
code the namespace prefix 'a4' as follows:

doc.CreateAttri bute("xmlns","a 4","http://www.w3.org/2000/xmlns/");
nsattr.InnerTex t =
"http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage/OsfDomai
n%2C%20Version% 3D1.0.0.1%2C%20 Culture%3Dneutr al%2C%20PublicK eyToken%3Dnull" ;
But what if I don't know what the prefix is? It seems that I should ask the
document
to generate a new one for me if one doesn't already exist. But on
XmlDocument I only
see:

GetPrefixOfName space and
GetNamespaceOfP refix

Paul

"Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
news:z%******** **********@TK2M SFTNGXA01.phx.g bl...
Hi Paul,

Welcome to MSDN newsgroup.
Regarding the adding XmlNode into XmlDocument question you mentioned, we
can just use the XmlDocument.Cre ateElement to create a Element xml node
and
then locate the parent node where we want to append the new element. Then,
we can use the XmlElement(XmlN ode) 's AppendChild method to add the new
element. Also, in your scenario, your element has some additional
namespace declaration attributes, we need to append them into the new
element or in the document also. here is a simple example on creating a
new
xmlelement and add into a existing xmldoument:

the original document is like:

=============== ==
<?xml version="1.0" encoding="utf-8" ?>
<root xmlns="http://www.mytest.org" >
<datas>
<data id="1">
<item>fsfdsfs </item>
</data>
<data id="2">
<item>fksfjkdsj fdks</item>
</data>
</datas>
</root>
=============== ====

the code that modify the document is:
=============== =====
static void RunXmlDoc()
{
XmlDocument doc = new XmlDocument();
doc.Load(@"..\. .\testxml.xml") ;

XmlElement elm = doc.CreateEleme nt("PayPerferen ce");

elm.InnerText = "cash";
XmlAttribute nsattr = null;

nsattr =
doc.CreateAttri bute("xmlns","x si","http://www.w3.org/2000/xmlns/");
nsattr.InnerTex t = "http://www.w3.org/2001/XMLSchema-instance";

elm.Attributes. Append(
nsattr
);

//
nsattr =
doc.CreateAttri bute("xmlns","a 4","http://www.w3.org/2000/xmlns/");
nsattr.InnerTex t =
"http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage/OsfDomai
n%2C%20Version% 3D1.0.0.1%2C%20 Culture%3Dneutr al%2C%20PublicK eyToken%3Dnull" ;

elm.Attributes. Append(
nsattr
);
nsattr =
doc.CreateAttri bute("xsi","typ e","http://www.w3.org/2001/XMLSchema-instance"
);
nsattr.InnerTex t = "a4:Customer+Cu stomerPayOption s";
elm.Attributes. Append(
nsattr
);

XmlNamespaceMan ager manager = new XmlNamespaceMan ager(doc.NameTa ble);
manager.AddName space("ns1","ht tp://www.mytest.org" );

XmlElement datas = doc.SelectSingl eNode("/ns1:root/ns1:datas",mana ger)
as XmlElement;

datas.AppendChi ld(elm);

Console.WriteLi ne(doc.OuterXml );

doc.Save("outpu t.xml");

}
=============== ============

The output.xml will be something like;

=============== =========
<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://www.mytest.org" >
<datas>
<data id="1">
<item>fsfdsfs </item>
</data>
<data id="2">
<item>fksfjkdsj fdks</item>
</data>
<PayPerferenc e xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xmlns:a4="http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage
/OsfDomain%2C%20 Version%3D1.0.0 .1%2C%20Culture %3Dneutral%2C%2 0PublicKeyToken
%3Dnull" xsi:type="a4:Cu stomer+Customer PayOptions"
xmlns="">cash</PayPerference>
</datas>
</root>
=============== =============

Also, you can find the the "PayPerfere nce" element in the output has an
empty default namespace

xmlns=""

you can explicitly specify the default namespace by changing the
XmlElement's construction to below:

XmlElement elm =
doc.CreateEleme nt("PayPerferen ce","http://www.mycustomapp .com");

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Paul" <pa*****@commun ity.nospam>
| Subject: Add XmlNode
| Date: Wed, 26 Oct 2005 11:29:29 -0700
| Lines: 28
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <uh************ *@TK2MSFTNGP15. phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.xml
| NNTP-Posting-Host: 66.236.123.34.p tr.us.xo.net 66.236.123.34
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP15.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl microsoft.publi c.dotnet.xml:90 85
| X-Tomcat-NG: microsoft.publi c.dotnet.xml
|
| Here I have the definition of an XmlNode which is a property
(PayPreference)
| on my Customer class containing an enum describing how the customer will
| pay.
|
| <PayPerferenc e xsi:type="a4:Cu stomer+Customer PayOptions"
|
xmlns:a4="http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage
/OsfDomain%2C%20 Version%3D1.0.0 .1%2C%20Culture %3Dneutral%2C%2 0PublicKeyToken
%3Dnull">cash</PayPerference>
|
| I now want to add this XmlNode to a different Xml file where the
Customer
| class has not defined a PayPreference property. I get as far as
locating
| the parent XmlNode (Customer). Now I just need to add the XmlNode
defined
| above. To do this, I understand that I need to ask the XmlDocument to
| create the node first before I ask the Customer node to 'AppendChild'.
I
| notice 3 overloads of CreateElement on the XmlDocument to do this:
|
| CreateElement(s tring name)
| CreateElement(s tring qualifiedName, string namespaceURI)
| CreateElement(s tring prefix, string localName, string namespaceURI)
|
| So now I'm stuck as to what I need to do now. Any help would be
| appreciated!
|
|
|
|
|
|
|
|
|

Nov 12 '05 #3
Thanks for your response Paul,

As for namespace prefix, it doesn't matter much. Namespace prefix is just
like an alias of the actual Namespace URI, so we can choose discretionary
ones as we like. And prefix value won't make XML document different as
long as the Namespace URI is the same between multiple documents.
e.g.

the following xmlelement is identical to each other:
[1]
<ns0:hello xmlns:ns0="http ://www.hello.org" >
<ns0:helloWorld >hello</ns0:helloWorld>
</ns0:hello>

[2]
<ns1:hello xmlns:ns1="http ://www.hello.org">
<ns1:helloWorld >hello</ns1:helloWorld>
</ns1:hello>

though the namespace prefix is different( "ns0" and "ns1"), their actual
Namespace URI are the same. So they're identical.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Paul" <pa*****@commun ity.nospam>
| References: <uh************ *@TK2MSFTNGP15. phx.gbl>
<z#************ **@TK2MSFTNGXA0 1.phx.gbl>
| Subject: Re: Add XmlNode
| Date: Thu, 27 Oct 2005 10:04:59 -0700
| Lines: 222
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <OY************ **@TK2MSFTNGP10 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.xml
| NNTP-Posting-Host: 66.236.123.34.p tr.us.xo.net 66.236.123.34
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl microsoft.publi c.dotnet.xml:91 00
| X-Tomcat-NG: microsoft.publi c.dotnet.xml
|
| Hello Steven and thank you for your reply!!
|
| Your solution worked well and it seems that
| the part I was missing was that I needed to ask
| the document to create the new XmlAttribute and not
| the newly created node.
|
| I do have a followup question. In your solution you hard-
| code the namespace prefix 'a4' as follows:
|
| doc.CreateAttri bute("xmlns","a 4","http://www.w3.org/2000/xmlns/");
| nsattr.InnerTex t =
|
"http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage/OsfDomai
|
n%2C%20Version% 3D1.0.0.1%2C%20 Culture%3Dneutr al%2C%20PublicK eyToken%3Dnull" ;
|
|
| But what if I don't know what the prefix is? It seems that I should ask
the
| document
| to generate a new one for me if one doesn't already exist. But on
| XmlDocument I only
| see:
|
| GetPrefixOfName space and
| GetNamespaceOfP refix
|
| Paul
|
|
|
| "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| news:z%******** **********@TK2M SFTNGXA01.phx.g bl...
| > Hi Paul,
| >
| > Welcome to MSDN newsgroup.
| > Regarding the adding XmlNode into XmlDocument question you mentioned, we
| > can just use the XmlDocument.Cre ateElement to create a Element xml node
| > and
| > then locate the parent node where we want to append the new element.
Then,
| > we can use the XmlElement(XmlN ode) 's AppendChild method to add the new
| > element. Also, in your scenario, your element has some additional
| > namespace declaration attributes, we need to append them into the new
| > element or in the document also. here is a simple example on creating a
| > new
| > xmlelement and add into a existing xmldoument:
| >
| > the original document is like:
| >
| > =============== ==
| > <?xml version="1.0" encoding="utf-8" ?>
| > <root xmlns="http://www.mytest.org" >
| > <datas>
| > <data id="1">
| > <item>fsfdsfs </item>
| > </data>
| > <data id="2">
| > <item>fksfjkdsj fdks</item>
| > </data>
| > </datas>
| > </root>
| > =============== ====
| >
| > the code that modify the document is:
| > =============== =====
| > static void RunXmlDoc()
| > {
| > XmlDocument doc = new XmlDocument();
| > doc.Load(@"..\. .\testxml.xml") ;
| >
| > XmlElement elm = doc.CreateEleme nt("PayPerferen ce");
| >
| > elm.InnerText = "cash";
| >
| >
| > XmlAttribute nsattr = null;
| >
| > nsattr =
| > doc.CreateAttri bute("xmlns","x si","http://www.w3.org/2000/xmlns/");
| > nsattr.InnerTex t = "http://www.w3.org/2001/XMLSchema-instance";
| >
| > elm.Attributes. Append(
| > nsattr
| > );
| >
| > //
| > nsattr =
| > doc.CreateAttri bute("xmlns","a 4","http://www.w3.org/2000/xmlns/");
| > nsattr.InnerTex t =
| >
"http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage/OsfDomai
| >
n%2C%20Version% 3D1.0.0.1%2C%20 Culture%3Dneutr al%2C%20PublicK eyToken%3Dnull" ;
| >
| > elm.Attributes. Append(
| > nsattr
| > );
| >
| >
| > nsattr =
| >
doc.CreateAttri bute("xsi","typ e","http://www.w3.org/2001/XMLSchema-instance"
| > );
| > nsattr.InnerTex t = "a4:Customer+Cu stomerPayOption s";
| > elm.Attributes. Append(
| > nsattr
| > );
| >
| > XmlNamespaceMan ager manager = new XmlNamespaceMan ager(doc.NameTa ble);
| > manager.AddName space("ns1","ht tp://www.mytest.org" );
| >
| > XmlElement datas = doc.SelectSingl eNode("/ns1:root/ns1:datas",mana ger)
| > as XmlElement;
| >
| > datas.AppendChi ld(elm);
| >
| >
| >
| > Console.WriteLi ne(doc.OuterXml );
| >
| > doc.Save("outpu t.xml");
| >
| > }
| > =============== ============
| >
| > The output.xml will be something like;
| >
| > =============== =========
| > <?xml version="1.0" encoding="utf-8"?>
| > <root xmlns="http://www.mytest.org" >
| > <datas>
| > <data id="1">
| > <item>fsfdsfs </item>
| > </data>
| > <data id="2">
| > <item>fksfjkdsj fdks</item>
| > </data>
| > <PayPerferenc e xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
| >
xmlns:a4="http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage
| >
/OsfDomain%2C%20 Version%3D1.0.0 .1%2C%20Culture %3Dneutral%2C%2 0PublicKeyToken
| > %3Dnull" xsi:type="a4:Cu stomer+Customer PayOptions"
| > xmlns="">cash</PayPerference>
| > </datas>
| > </root>
| > =============== =============
| >
| > Also, you can find the the "PayPerfere nce" element in the output has an
| > empty default namespace
| >
| > xmlns=""
| >
| > you can explicitly specify the default namespace by changing the
| > XmlElement's construction to below:
| >
| > XmlElement elm =
| > doc.CreateEleme nt("PayPerferen ce","http://www.mycustomapp .com");
| >
| > Hope helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| >
| >
| > --------------------
| > | From: "Paul" <pa*****@commun ity.nospam>
| > | Subject: Add XmlNode
| > | Date: Wed, 26 Oct 2005 11:29:29 -0700
| > | Lines: 28
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| > | X-RFC2646: Format=Flowed; Original
| > | Message-ID: <uh************ *@TK2MSFTNGP15. phx.gbl>
| > | Newsgroups: microsoft.publi c.dotnet.xml
| > | NNTP-Posting-Host: 66.236.123.34.p tr.us.xo.net 66.236.123.34
| > | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP15.phx. gbl
| > | Xref: TK2MSFTNGXA01.p hx.gbl microsoft.publi c.dotnet.xml:90 85
| > | X-Tomcat-NG: microsoft.publi c.dotnet.xml
| > |
| > | Here I have the definition of an XmlNode which is a property
| > (PayPreference)
| > | on my Customer class containing an enum describing how the customer
will
| > | pay.
| > |
| > | <PayPerferenc e xsi:type="a4:Cu stomer+Customer PayOptions"
| > |
| >
xmlns:a4="http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage
| >
/OsfDomain%2C%20 Version%3D1.0.0 .1%2C%20Culture %3Dneutral%2C%2 0PublicKeyToken
| > %3Dnull">cash</PayPerference>
| > |
| > | I now want to add this XmlNode to a different Xml file where the
| > Customer
| > | class has not defined a PayPreference property. I get as far as
| > locating
| > | the parent XmlNode (Customer). Now I just need to add the XmlNode
| > defined
| > | above. To do this, I understand that I need to ask the XmlDocument to
| > | create the node first before I ask the Customer node to
'AppendChild'.
| > I
| > | notice 3 overloads of CreateElement on the XmlDocument to do this:
| > |
| > | CreateElement(s tring name)
| > | CreateElement(s tring qualifiedName, string namespaceURI)
| > | CreateElement(s tring prefix, string localName, string
namespaceURI)
| > |
| > | So now I'm stuck as to what I need to do now. Any help would be
| > | appreciated!
| > |
| > |
| > |
| > |
| > |
| > |
| > |
| > |
| > |
| >
|
|
|

Nov 12 '05 #4
Thanks again, Steven.

Based on your response, the approach I'm going to take is to generate the
prefixes myself which I've implemented and it appears to work.

Anyway, your help got me out of a corner, thank you.

Paul

"Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
news:sp******** ******@TK2MSFTN GXA01.phx.gbl.. .
Thanks for your response Paul,

As for namespace prefix, it doesn't matter much. Namespace prefix is just
like an alias of the actual Namespace URI, so we can choose discretionary
ones as we like. And prefix value won't make XML document different as
long as the Namespace URI is the same between multiple documents.
e.g.

the following xmlelement is identical to each other:
[1]
<ns0:hello xmlns:ns0="http ://www.hello.org" >
<ns0:helloWorld >hello</ns0:helloWorld>
</ns0:hello>

[2]
<ns1:hello xmlns:ns1="http ://www.hello.org">
<ns1:helloWorld >hello</ns1:helloWorld>
</ns1:hello>

though the namespace prefix is different( "ns0" and "ns1"), their actual
Namespace URI are the same. So they're identical.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Paul" <pa*****@commun ity.nospam>
| References: <uh************ *@TK2MSFTNGP15. phx.gbl>
<z#************ **@TK2MSFTNGXA0 1.phx.gbl>
| Subject: Re: Add XmlNode
| Date: Thu, 27 Oct 2005 10:04:59 -0700
| Lines: 222
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <OY************ **@TK2MSFTNGP10 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.xml
| NNTP-Posting-Host: 66.236.123.34.p tr.us.xo.net 66.236.123.34
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl microsoft.publi c.dotnet.xml:91 00
| X-Tomcat-NG: microsoft.publi c.dotnet.xml
|
| Hello Steven and thank you for your reply!!
|
| Your solution worked well and it seems that
| the part I was missing was that I needed to ask
| the document to create the new XmlAttribute and not
| the newly created node.
|
| I do have a followup question. In your solution you hard-
| code the namespace prefix 'a4' as follows:
|
| doc.CreateAttri bute("xmlns","a 4","http://www.w3.org/2000/xmlns/");
| nsattr.InnerTex t =
|
"http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage/OsfDomai
|
n%2C%20Version% 3D1.0.0.1%2C%20 Culture%3Dneutr al%2C%20PublicK eyToken%3Dnull" ;
|
|
| But what if I don't know what the prefix is? It seems that I should ask
the
| document
| to generate a new one for me if one doesn't already exist. But on
| XmlDocument I only
| see:
|
| GetPrefixOfName space and
| GetNamespaceOfP refix
|
| Paul
|
|
|
| "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| news:z%******** **********@TK2M SFTNGXA01.phx.g bl...
| > Hi Paul,
| >
| > Welcome to MSDN newsgroup.
| > Regarding the adding XmlNode into XmlDocument question you mentioned,
we
| > can just use the XmlDocument.Cre ateElement to create a Element xml
node
| > and
| > then locate the parent node where we want to append the new element.
Then,
| > we can use the XmlElement(XmlN ode) 's AppendChild method to add the
new
| > element. Also, in your scenario, your element has some additional
| > namespace declaration attributes, we need to append them into the new
| > element or in the document also. here is a simple example on creating
a
| > new
| > xmlelement and add into a existing xmldoument:
| >
| > the original document is like:
| >
| > =============== ==
| > <?xml version="1.0" encoding="utf-8" ?>
| > <root xmlns="http://www.mytest.org" >
| > <datas>
| > <data id="1">
| > <item>fsfdsfs </item>
| > </data>
| > <data id="2">
| > <item>fksfjkdsj fdks</item>
| > </data>
| > </datas>
| > </root>
| > =============== ====
| >
| > the code that modify the document is:
| > =============== =====
| > static void RunXmlDoc()
| > {
| > XmlDocument doc = new XmlDocument();
| > doc.Load(@"..\. .\testxml.xml") ;
| >
| > XmlElement elm = doc.CreateEleme nt("PayPerferen ce");
| >
| > elm.InnerText = "cash";
| >
| >
| > XmlAttribute nsattr = null;
| >
| > nsattr =
| > doc.CreateAttri bute("xmlns","x si","http://www.w3.org/2000/xmlns/");
| > nsattr.InnerTex t = "http://www.w3.org/2001/XMLSchema-instance";
| >
| > elm.Attributes. Append(
| > nsattr
| > );
| >
| > //
| > nsattr =
| > doc.CreateAttri bute("xmlns","a 4","http://www.w3.org/2000/xmlns/");
| > nsattr.InnerTex t =
| >
"http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage/OsfDomai
| >
n%2C%20Version% 3D1.0.0.1%2C%20 Culture%3Dneutr al%2C%20PublicK eyToken%3Dnull" ;
| >
| > elm.Attributes. Append(
| > nsattr
| > );
| >
| >
| > nsattr =
| >
doc.CreateAttri bute("xsi","typ e","http://www.w3.org/2001/XMLSchema-instance"
| > );
| > nsattr.InnerTex t = "a4:Customer+Cu stomerPayOption s";
| > elm.Attributes. Append(
| > nsattr
| > );
| >
| > XmlNamespaceMan ager manager = new XmlNamespaceMan ager(doc.NameTa ble);
| > manager.AddName space("ns1","ht tp://www.mytest.org" );
| >
| > XmlElement datas = doc.SelectSingl eNode("/ns1:root/ns1:datas",mana ger)
| > as XmlElement;
| >
| > datas.AppendChi ld(elm);
| >
| >
| >
| > Console.WriteLi ne(doc.OuterXml );
| >
| > doc.Save("outpu t.xml");
| >
| > }
| > =============== ============
| >
| > The output.xml will be something like;
| >
| > =============== =========
| > <?xml version="1.0" encoding="utf-8"?>
| > <root xmlns="http://www.mytest.org" >
| > <datas>
| > <data id="1">
| > <item>fsfdsfs </item>
| > </data>
| > <data id="2">
| > <item>fksfjkdsj fdks</item>
| > </data>
| > <PayPerferenc e
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
| >
xmlns:a4="http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage
| >
/OsfDomain%2C%20 Version%3D1.0.0 .1%2C%20Culture %3Dneutral%2C%2 0PublicKeyToken
| > %3Dnull" xsi:type="a4:Cu stomer+Customer PayOptions"
| > xmlns="">cash</PayPerference>
| > </datas>
| > </root>
| > =============== =============
| >
| > Also, you can find the the "PayPerfere nce" element in the output has
an
| > empty default namespace
| >
| > xmlns=""
| >
| > you can explicitly specify the default namespace by changing the
| > XmlElement's construction to below:
| >
| > XmlElement elm =
| > doc.CreateEleme nt("PayPerferen ce","http://www.mycustomapp .com");
| >
| > Hope helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| >
| >
| > --------------------
| > | From: "Paul" <pa*****@commun ity.nospam>
| > | Subject: Add XmlNode
| > | Date: Wed, 26 Oct 2005 11:29:29 -0700
| > | Lines: 28
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| > | X-RFC2646: Format=Flowed; Original
| > | Message-ID: <uh************ *@TK2MSFTNGP15. phx.gbl>
| > | Newsgroups: microsoft.publi c.dotnet.xml
| > | NNTP-Posting-Host: 66.236.123.34.p tr.us.xo.net 66.236.123.34
| > | Path:
TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP15.phx. gbl
| > | Xref: TK2MSFTNGXA01.p hx.gbl microsoft.publi c.dotnet.xml:90 85
| > | X-Tomcat-NG: microsoft.publi c.dotnet.xml
| > |
| > | Here I have the definition of an XmlNode which is a property
| > (PayPreference)
| > | on my Customer class containing an enum describing how the customer
will
| > | pay.
| > |
| > | <PayPerferenc e xsi:type="a4:Cu stomer+Customer PayOptions"
| > |
| >
xmlns:a4="http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage
| >
/OsfDomain%2C%20 Version%3D1.0.0 .1%2C%20Culture %3Dneutral%2C%2 0PublicKeyToken
| > %3Dnull">cash</PayPerference>
| > |
| > | I now want to add this XmlNode to a different Xml file where the
| > Customer
| > | class has not defined a PayPreference property. I get as far as
| > locating
| > | the parent XmlNode (Customer). Now I just need to add the XmlNode
| > defined
| > | above. To do this, I understand that I need to ask the XmlDocument
to
| > | create the node first before I ask the Customer node to
'AppendChild'.
| > I
| > | notice 3 overloads of CreateElement on the XmlDocument to do this:
| > |
| > | CreateElement(s tring name)
| > | CreateElement(s tring qualifiedName, string namespaceURI)
| > | CreateElement(s tring prefix, string localName, string
namespaceURI)
| > |
| > | So now I'm stuck as to what I need to do now. Any help would be
| > | appreciated!
| > |
| > |
| > |
| > |
| > |
| > |
| > |
| > |
| > |
| >
|
|
|

Nov 12 '05 #5
You're welcome Paul.

Good luck!

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Paul" <pa*****@commun ity.nospam>
| References: <uh************ *@TK2MSFTNGP15. phx.gbl>
<z#************ **@TK2MSFTNGXA0 1.phx.gbl>
<OY************ **@TK2MSFTNGP10 .phx.gbl>
<sp************ **@TK2MSFTNGXA0 1.phx.gbl>
| Subject: Re: Add XmlNode
| Date: Fri, 28 Oct 2005 11:32:13 -0700
| Lines: 311
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <Oi************ **@TK2MSFTNGP12 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.xml
| NNTP-Posting-Host: 66.236.123.34.p tr.us.xo.net 66.236.123.34
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl microsoft.publi c.dotnet.xml:91 11
| X-Tomcat-NG: microsoft.publi c.dotnet.xml
|
| Thanks again, Steven.
|
| Based on your response, the approach I'm going to take is to generate the
| prefixes myself which I've implemented and it appears to work.
|
| Anyway, your help got me out of a corner, thank you.
|
| Paul
|
| "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| news:sp******** ******@TK2MSFTN GXA01.phx.gbl.. .
| > Thanks for your response Paul,
| >
| > As for namespace prefix, it doesn't matter much. Namespace prefix is
just
| > like an alias of the actual Namespace URI, so we can choose
discretionary
| > ones as we like. And prefix value won't make XML document different as
| > long as the Namespace URI is the same between multiple documents.
| > e.g.
| >
| > the following xmlelement is identical to each other:
| > [1]
| > <ns0:hello xmlns:ns0="http ://www.hello.org" >
| > <ns0:helloWorld >hello</ns0:helloWorld>
| > </ns0:hello>
| >
| > [2]
| > <ns1:hello xmlns:ns1="http ://www.hello.org">
| > <ns1:helloWorld >hello</ns1:helloWorld>
| > </ns1:hello>
| >
| > though the namespace prefix is different( "ns0" and "ns1"), their actual
| > Namespace URI are the same. So they're identical.
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| > --------------------
| > | From: "Paul" <pa*****@commun ity.nospam>
| > | References: <uh************ *@TK2MSFTNGP15. phx.gbl>
| > <z#************ **@TK2MSFTNGXA0 1.phx.gbl>
| > | Subject: Re: Add XmlNode
| > | Date: Thu, 27 Oct 2005 10:04:59 -0700
| > | Lines: 222
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| > | X-RFC2646: Format=Flowed; Original
| > | Message-ID: <OY************ **@TK2MSFTNGP10 .phx.gbl>
| > | Newsgroups: microsoft.publi c.dotnet.xml
| > | NNTP-Posting-Host: 66.236.123.34.p tr.us.xo.net 66.236.123.34
| > | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
| > | Xref: TK2MSFTNGXA01.p hx.gbl microsoft.publi c.dotnet.xml:91 00
| > | X-Tomcat-NG: microsoft.publi c.dotnet.xml
| > |
| > | Hello Steven and thank you for your reply!!
| > |
| > | Your solution worked well and it seems that
| > | the part I was missing was that I needed to ask
| > | the document to create the new XmlAttribute and not
| > | the newly created node.
| > |
| > | I do have a followup question. In your solution you hard-
| > | code the namespace prefix 'a4' as follows:
| > |
| > | doc.CreateAttri bute("xmlns","a 4","http://www.w3.org/2000/xmlns/");
| > | nsattr.InnerTex t =
| > |
| >
"http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage/OsfDomai
| > |
| >
n%2C%20Version% 3D1.0.0.1%2C%20 Culture%3Dneutr al%2C%20PublicK eyToken%3Dnull" ;
| > |
| > |
| > | But what if I don't know what the prefix is? It seems that I should
ask
| > the
| > | document
| > | to generate a new one for me if one doesn't already exist. But on
| > | XmlDocument I only
| > | see:
| > |
| > | GetPrefixOfName space and
| > | GetNamespaceOfP refix
| > |
| > | Paul
| > |
| > |
| > |
| > | "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| > | news:z%******** **********@TK2M SFTNGXA01.phx.g bl...
| > | > Hi Paul,
| > | >
| > | > Welcome to MSDN newsgroup.
| > | > Regarding the adding XmlNode into XmlDocument question you
mentioned,
| > we
| > | > can just use the XmlDocument.Cre ateElement to create a Element xml
| > node
| > | > and
| > | > then locate the parent node where we want to append the new element.
| > Then,
| > | > we can use the XmlElement(XmlN ode) 's AppendChild method to add the
| > new
| > | > element. Also, in your scenario, your element has some additional
| > | > namespace declaration attributes, we need to append them into the
new
| > | > element or in the document also. here is a simple example on
creating
| > a
| > | > new
| > | > xmlelement and add into a existing xmldoument:
| > | >
| > | > the original document is like:
| > | >
| > | > =============== ==
| > | > <?xml version="1.0" encoding="utf-8" ?>
| > | > <root xmlns="http://www.mytest.org" >
| > | > <datas>
| > | > <data id="1">
| > | > <item>fsfdsfs </item>
| > | > </data>
| > | > <data id="2">
| > | > <item>fksfjkdsj fdks</item>
| > | > </data>
| > | > </datas>
| > | > </root>
| > | > =============== ====
| > | >
| > | > the code that modify the document is:
| > | > =============== =====
| > | > static void RunXmlDoc()
| > | > {
| > | > XmlDocument doc = new XmlDocument();
| > | > doc.Load(@"..\. .\testxml.xml") ;
| > | >
| > | > XmlElement elm = doc.CreateEleme nt("PayPerferen ce");
| > | >
| > | > elm.InnerText = "cash";
| > | >
| > | >
| > | > XmlAttribute nsattr = null;
| > | >
| > | > nsattr =
| > | > doc.CreateAttri bute("xmlns","x si","http://www.w3.org/2000/xmlns/");
| > | > nsattr.InnerTex t = "http://www.w3.org/2001/XMLSchema-instance";
| > | >
| > | > elm.Attributes. Append(
| > | > nsattr
| > | > );
| > | >
| > | > //
| > | > nsattr =
| > | > doc.CreateAttri bute("xmlns","a 4","http://www.w3.org/2000/xmlns/");
| > | > nsattr.InnerTex t =
| > | >
| >
"http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage/OsfDomai
| > | >
| >
n%2C%20Version% 3D1.0.0.1%2C%20 Culture%3Dneutr al%2C%20PublicK eyToken%3Dnull" ;
| > | >
| > | > elm.Attributes. Append(
| > | > nsattr
| > | > );
| > | >
| > | >
| > | > nsattr =
| > | >
| >
doc.CreateAttri bute("xsi","typ e","http://www.w3.org/2001/XMLSchema-instance"
| > | > );
| > | > nsattr.InnerTex t = "a4:Customer+Cu stomerPayOption s";
| > | > elm.Attributes. Append(
| > | > nsattr
| > | > );
| > | >
| > | > XmlNamespaceMan ager manager = new
XmlNamespaceMan ager(doc.NameTa ble);
| > | > manager.AddName space("ns1","ht tp://www.mytest.org" );
| > | >
| > | > XmlElement datas =
doc.SelectSingl eNode("/ns1:root/ns1:datas",mana ger)
| > | > as XmlElement;
| > | >
| > | > datas.AppendChi ld(elm);
| > | >
| > | >
| > | >
| > | > Console.WriteLi ne(doc.OuterXml );
| > | >
| > | > doc.Save("outpu t.xml");
| > | >
| > | > }
| > | > =============== ============
| > | >
| > | > The output.xml will be something like;
| > | >
| > | > =============== =========
| > | > <?xml version="1.0" encoding="utf-8"?>
| > | > <root xmlns="http://www.mytest.org" >
| > | > <datas>
| > | > <data id="1">
| > | > <item>fsfdsfs </item>
| > | > </data>
| > | > <data id="2">
| > | > <item>fksfjkdsj fdks</item>
| > | > </data>
| > | > <PayPerferenc e
| > xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
| > | >
| >
xmlns:a4="http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage
| > | >
| >
/OsfDomain%2C%20 Version%3D1.0.0 .1%2C%20Culture %3Dneutral%2C%2 0PublicKeyToken
| > | > %3Dnull" xsi:type="a4:Cu stomer+Customer PayOptions"
| > | > xmlns="">cash</PayPerference>
| > | > </datas>
| > | > </root>
| > | > =============== =============
| > | >
| > | > Also, you can find the the "PayPerfere nce" element in the output
has
| > an
| > | > empty default namespace
| > | >
| > | > xmlns=""
| > | >
| > | > you can explicitly specify the default namespace by changing the
| > | > XmlElement's construction to below:
| > | >
| > | > XmlElement elm =
| > | > doc.CreateEleme nt("PayPerferen ce","http://www.mycustomapp .com");
| > | >
| > | > Hope helps. Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | >
| > | >
| > | >
| > | >
| > | >
| > | > --------------------
| > | > | From: "Paul" <pa*****@commun ity.nospam>
| > | > | Subject: Add XmlNode
| > | > | Date: Wed, 26 Oct 2005 11:29:29 -0700
| > | > | Lines: 28
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| > | > | X-RFC2646: Format=Flowed; Original
| > | > | Message-ID: <uh************ *@TK2MSFTNGP15. phx.gbl>
| > | > | Newsgroups: microsoft.publi c.dotnet.xml
| > | > | NNTP-Posting-Host: 66.236.123.34.p tr.us.xo.net 66.236.123.34
| > | > | Path:
| > TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP15.phx. gbl
| > | > | Xref: TK2MSFTNGXA01.p hx.gbl microsoft.publi c.dotnet.xml:90 85
| > | > | X-Tomcat-NG: microsoft.publi c.dotnet.xml
| > | > |
| > | > | Here I have the definition of an XmlNode which is a property
| > | > (PayPreference)
| > | > | on my Customer class containing an enum describing how the
customer
| > will
| > | > | pay.
| > | > |
| > | > | <PayPerferenc e xsi:type="a4:Cu stomer+Customer PayOptions"
| > | > |
| > | >
| >
xmlns:a4="http://schemas.microso ft.com/clr/nsassem/OsfDomain.Resou rces.Stage
| > | >
| >
/OsfDomain%2C%20 Version%3D1.0.0 .1%2C%20Culture %3Dneutral%2C%2 0PublicKeyToken
| > | > %3Dnull">cash</PayPerference>
| > | > |
| > | > | I now want to add this XmlNode to a different Xml file where the
| > | > Customer
| > | > | class has not defined a PayPreference property. I get as far as
| > | > locating
| > | > | the parent XmlNode (Customer). Now I just need to add the XmlNode
| > | > defined
| > | > | above. To do this, I understand that I need to ask the
XmlDocument
| > to
| > | > | create the node first before I ask the Customer node to
| > 'AppendChild'.
| > | > I
| > | > | notice 3 overloads of CreateElement on the XmlDocument to do this:
| > | > |
| > | > | CreateElement(s tring name)
| > | > | CreateElement(s tring qualifiedName, string namespaceURI)
| > | > | CreateElement(s tring prefix, string localName, string
| > namespaceURI)
| > | > |
| > | > | So now I'm stuck as to what I need to do now. Any help would be
| > | > | appreciated!
| > | > |
| > | > |
| > | > |
| > | > |
| > | > |
| > | > |
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 12 '05 #6

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

Similar topics

9
8133
by: JJ | last post by:
Hi All, I noticed that XmlNode and XpathNavigator are quite similiar. XmlNode seems to navigate over an XML Doc and so does XPathNav so when do I use XPathNavigator instead of XmlNode? Thanks, JJ
3
8120
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to run the class it gives an error that "System.Xml.XmlNode.XmlNode() is inaccessible due to its protection level". This error comes because XmlNode has not any public constructor. I found XmlNode has two constructor but both are private or friend...
1
4744
by: andrej | last post by:
hi, ich habe eine anwendung, welche ein xml document erstellt. um festzustellen, ob ein element bereits vorhanden ist, verwende ich die funktion selectsinglenode( ....) diese funktion liefert mir ein element des typs node.
5
2144
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to run the class it gives an error that "System.Xml.XmlNode.XmlNode() is inaccessible due to its protection level". This error comes because XmlNode has not any public constructor. I found XmlNode has two constructor but both are private or friend...
3
5060
by: Mae | last post by:
Dear All, I have a problem here, I'm using C# Webform calling a webservices. The webservices return me a XMLnode, using this XMLnode I want to convert it to dataset so I can bind to the datagrid, by extracting the <CustomerData></CustomerData> block from the xmlnode. Below is the sample of xmlnode return from webservices. <?xml version="1.0" encoding="utf-8"?>
1
313
by: PaulF | last post by:
I am writing a web service that accepts and returns an XML message - I know the issues behind this but want to be able to process the messages generically using XSD / XSLT. My problem occurs with the way the .NET framework appears to handle the XmlNode, in particular the generation of the WSDL. The details follow: I define the code behind method as
3
2883
by: Earl | last post by:
In VB.Net, the following declaration builds and executes with no exceptions: Dim XMLDoc As New XmlDocument Dim Node As XmlNode But in C#, the following (equivalent?!) returns the build error "XMLNode does not exist in the current context.": XmlDocument XMLDoc = new XmlDocument(); XmlNode Node = XMLNode;
5
2717
by: =?Utf-8?B?VGhlIE1hbiBGcm9tIFNRTA==?= | last post by:
I'm having the darndest XML config file problem that I really need help with. I'm supporting a .NET 1.1 desktop application with its own config file, and I implement IConfigurationSectionHandler so I can have a custom config section in my config file. The IConfigurationSectionHandler.Create method just returns the 'section' XmlNode back to the consumer. The config file looks kind of like this: <?xml version="1.0" encoding="utf-8" ?>...
2
4629
by: =?iso-8859-1?Q?Norbert_P=FCrringer?= | last post by:
Hello! Is it possible to use the object XMLNode as a parameter in an interface function of a WCF service? In my case I get the error message: XmlNode ProcessServiceRequest(XmlNode request); Unable to serialize type "System.Xml.XmlNode". Use the attribute
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9538
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10219
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10025
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6804
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5461
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5584
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.