473,394 Members | 1,702 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,394 software developers and data experts.

XmlNode adds NamespaceURI

Hello,

I wish to copy an XmlNode in a string variable from a XmlDocument object.
But as I takeout this XmlNode, it adds the NamespaceURI. Why ? Could
somebody please help me ?

Vivek
Apr 3 '06 #1
6 1956


Vivek wrote:

I wish to copy an XmlNode in a string variable from a XmlDocument object.
node.OuterXml serializes a node to a string.
But as I takeout this XmlNode, it adds the NamespaceURI. Why ?


Well why not? The namespaceURI is an essential part of any element or
attribute node, just like the local name to identify the node correctly.
If serialization would not declare namespaces then it would not work
correctly.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 3 '06 #2
OK. But I want to deserialize this node with serializer.deserialize. And it
gives the exception that "<Nodename xmlns="thisNamespace"> was not expected.
"Martin Honnen" <ma*******@yahoo.de> a écrit dans le message de news:
%2******************@TK2MSFTNGP11.phx.gbl...


Vivek wrote:

I wish to copy an XmlNode in a string variable from a XmlDocument object.


node.OuterXml serializes a node to a string.
But as I takeout this XmlNode, it adds the NamespaceURI. Why ?


Well why not? The namespaceURI is an essential part of any element or
attribute node, just like the local name to identify the node correctly.
If serialization would not declare namespaces then it would not work
correctly.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Apr 3 '06 #3


Vivek wrote:
But I want to deserialize this node with serializer.deserialize. And it
gives the exception that "<Nodename xmlns="thisNamespace"> was not expected.


Provide some more details on the .NET types used, the serialization
attributes you have and why/how you get (serialize?) the node first to
have the wrong namespace.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 3 '06 #4
Here is the code :
try
{
// serialise to object
XmlSerializer serializer = new
XmlSerializer(typeof(childactivitiesactivity)); //I use
childactivitiesactivity in place of "child" to get only this branch
sreader = new StringReader(node); // read xml data
reader = new XmlTextReader(sreader); // create reader
// convert reader to object
facture =
(childactivitiesactivity)serializer.Deserialize(re ader);
}
catch
{
throw new InvalidOperationException();
}
finally
{
if (sreader != null) sreader.Close();
if (reader != null) reader.Close();
}

the xml file looks like this,

<child>
<profile></profile>
<adress></adress>
<activities>
<activity></activity>
<activity></activity>
</activities>
</child>

I have created the classes with xsd.exe. It has created a table of
activities[] to fill up with activity nodes. While I deserialize, it gives a
table activities with dimensions=0. As I found, on internet that its a bug
of .net, I wanted to fetch the table like the code as above, i.e., passing a
table of "childactivitiesactivity" directly. now, I have started having a
doubt if ever I can deserialize this branch only instead of the whole tree.
Otherwise, I am thinking to use XmlDocument, if it does not work.

Vivek
Apr 3 '06 #5
Please also post the class. Your sample XML probably has a namespace
declaration too right? So try adding an
[System.Xml.Serialization.XmlRoot(Namespace="thisNa mespace")]attribute on
your class. Then the serializer should be happy.

"Vivek" <vi**************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Here is the code :
try
{
// serialise to object
XmlSerializer serializer = new
XmlSerializer(typeof(childactivitiesactivity)); //I use
childactivitiesactivity in place of "child" to get only this branch
sreader = new StringReader(node); // read xml data
reader = new XmlTextReader(sreader); // create reader
// convert reader to object
facture =
(childactivitiesactivity)serializer.Deserialize(re ader);
}
catch
{
throw new InvalidOperationException();
}
finally
{
if (sreader != null) sreader.Close();
if (reader != null) reader.Close();
}

the xml file looks like this,

<child>
<profile></profile>
<adress></adress>
<activities>
<activity></activity>
<activity></activity>
</activities>
</child>

I have created the classes with xsd.exe. It has created a table of
activities[] to fill up with activity nodes. While I deserialize, it gives
a table activities with dimensions=0. As I found, on internet that its a
bug of .net, I wanted to fetch the table like the code as above, i.e.,
passing a table of "childactivitiesactivity" directly. now, I have started
having a doubt if ever I can deserialize this branch only instead of the
whole tree.
Otherwise, I am thinking to use XmlDocument, if it does not work.

Vivek

Apr 5 '06 #6
Sorry for the delay. Here is the code for this class, which I created with
xsd.exe from XSD file.


//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.42
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

//
// This source code was auto-generated by xsd, Version=2.0.50727.42.
//
namespace Esvicom.FichierXml {
using System.Xml.Serialization;
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xs d", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Xml.Serialization.XmlTypeAttribute(Anonymou sType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespac e="http://www.esvicom.org/enfants",
IsNullable=false)]
public partial class enfant {

private object[] itemsField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("adre sse_placeur",
typeof(enfantAdresse_placeur))]
[System.Xml.Serialization.XmlElementAttribute("fact ures",
typeof(enfantFacturesFacture[]))]
[System.Xml.Serialization.XmlElementAttribute("prof il",
typeof(enfantProfil))]
public object[] Items {
get {
return this.itemsField;
}
set {
this.itemsField = value;
}
}
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xs d", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Xml.Serialization.XmlTypeAttribute(Anonymou sType=true)]
public partial class enfantAdresse_placeur {

private string[] adresseField;

private string code_postalField;

private string villeField;

private string departmentField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("adre sse",
IsNullable=true)]
public string[] adresse {
get {
return this.adresseField;
}
set {
this.adresseField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataT ype="positiveInteger")]
public string code_postal {
get {
return this.code_postalField;
}
set {
this.code_postalField = value;
}
}

/// <remarks/>
public string ville {
get {
return this.villeField;
}
set {
this.villeField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Dat aType="positiveInteger")]
public string department {
get {
return this.departmentField;
}
set {
this.departmentField = value;
}
}
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xs d", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Xml.Serialization.XmlTypeAttribute(Anonymou sType=true)]
public partial class enfantFacturesFacture {

private string nb_jours_totauxField;

private string nb_presencesField;

private string nb_absencesField;

private string presencesfacturesField;

private string absencesfacturesField;

private decimal montant_presencesField;

private decimal montant_absencesField;

private decimal montant_totalField;

private System.DateTime dateField;

private string periodeField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataT ype="positiveInteger")]
public string nb_jours_totaux {
get {
return this.nb_jours_totauxField;
}
set {
this.nb_jours_totauxField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataT ype="positiveInteger")]
public string nb_presences {
get {
return this.nb_presencesField;
}
set {
this.nb_presencesField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataT ype="nonNegativeInteger")]
public string nb_absences {
get {
return this.nb_absencesField;
}
set {
this.nb_absencesField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataT ype="positiveInteger")]
public string presencesfactures {
get {
return this.presencesfacturesField;
}
set {
this.presencesfacturesField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataT ype="nonNegativeInteger")]
public string absencesfactures {
get {
return this.absencesfacturesField;
}
set {
this.absencesfacturesField = value;
}
}

/// <remarks/>
public decimal montant_presences {
get {
return this.montant_presencesField;
}
set {
this.montant_presencesField = value;
}
}

/// <remarks/>
public decimal montant_absences {
get {
return this.montant_absencesField;
}
set {
this.montant_absencesField = value;
}
}

/// <remarks/>
public decimal montant_total {
get {
return this.montant_totalField;
}
set {
this.montant_totalField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Dat aType="date")]
public System.DateTime date {
get {
return this.dateField;
}
set {
this.dateField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string periode {
get {
return this.periodeField;
}
set {
this.periodeField = value;
}
}
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xs d", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Xml.Serialization.XmlTypeAttribute(Anonymou sType=true)]
public partial class enfantProfil {

private string nomField;

private string prenomField;

private System.DateTime date_darriveeField;

private decimal prix_journalierField;

private string nb_jours_vacances_à_100pcField;

private string pourcentage_decompteField;

/// <remarks/>
public string nom {
get {
return this.nomField;
}
set {
this.nomField = value;
}
}

/// <remarks/>
public string prenom {
get {
return this.prenomField;
}
set {
this.prenomField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataT ype="date")]
public System.DateTime date_darrivee {
get {
return this.date_darriveeField;
}
set {
this.date_darriveeField = value;
}
}

/// <remarks/>
public decimal prix_journalier {
get {
return this.prix_journalierField;
}
set {
this.prix_journalierField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataT ype="integer")]
public string nb_jours_vacances_à_100pc {
get {
return this.nb_jours_vacances_à_100pcField;
}
set {
this.nb_jours_vacances_à_100pcField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataT ype="positiveInteger")]
public string pourcentage_decompte {
get {
return this.pourcentage_decompteField;
}
set {
this.pourcentage_decompteField = value;
}
}
}
}
Apr 7 '06 #7

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

Similar topics

5
by: Ian Williamson | last post by:
Greetings, I have seen this question posted a few times, but the answers have not helped me. I have used the program xsd.exe to generate several c# classes from a client provided xsd...
2
by: Eirik M. | last post by:
Can anyone from M$ or anyone else for that matter explain to me the reasoning behind the intended usage for this property? I was quite surprised to find that this property may be null depending on...
3
by: Dan | last post by:
I've loaded the following xml into an XMLDocument object: <?xml version="1.0" ?> - <Preferences> <Institution>Argh</Institution> <Speaker>Chigier, Ben (1234)</Speaker>...
3
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...
4
by: Guy | last post by:
Hi, I read an XML file to an XMLDocument and iterate through its nodes. How do I get the XPath position (index) of a certain element? For example If I on the second "b" node I want to get "2": ...
5
by: Paul | last post by:
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. <PayPerference...
1
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...
5
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...
0
by: Vivek | last post by:
Hello, I wish to copy an XmlNode in a string variable from a XmlDocument object. But as I takeout this XmlNode, it adds the NamespaceURI. Why ? Could somebody please help me ? Vivek
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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.