q1 ???

This is probably easy, but I have spent several hours trying to get it to 
work with no luck.

I'm just using the XmlSerializer class to write an XML file:

XmlSerializer s = new XmlSerializer(typeof(myType));;
XmlSerializerNamespaces n = new XmlSerializerNamespaces();
n.Add(string.Empy, string.Empy);
Stream fs = new FileStream(name, FileMode.Create);
XmlTextWriter tw = new XmlTextWriter(fs, Encoding.UTF8);
tw.Formatting = Formatting.None;
s.Serialize(tw, myObject, n);
tw.Close();

Anyway, the above works almost to what I want, but it produces the following 
XML file:

<?xml version="1.0" encoding="utf-8" ?>
<q1:myObjElement1 xmlns:q1="myXSD.xsd">
  <MyElement2>
    <MyElement3>
    </MyElement3>
  </MyElement2>
</q1:myObjeElement1>

My problem is that I want to get rid of that "q1:" string, and just 
serialize my object into XML.  What is the "q1:" string anyway, and why is 
it there?

I can get rid of the "q1:" string by changing the following attribute in my 
code from:

[System.Xml.Serialization.XmlRootAttribute(IsNullable = false, 
Namespace="myXSD.xsd")];

to:

[System.Xml.Serialization.XmlRootAttribute(IsNullable = false)];

However, if I do that, then I get:
<?xml version="1.0" encoding="utf-8" ?>
<myObjElement1>
  <MyElement2>
    <MyElement3>
    </MyElement3>
  </MyElement2>
</myObjeElement1>

The problem here is that I need the line:

<myObjElement1>

to really read:

<myObjElement1 xmlns="myXSD.xsd">


So in short:
How can I get rid of the "q1:" string and keep the xmlns attribute in my 
root element?

Thank you.



0
6/3/2008 8:07:57 PM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
1308 Views

Similar Articles

[PageSpeed] 57

"Tom" <johnthompson1@hotmail.com> wrote in message 
news:A9705A0F-A43A-411A-A012-1B8B97526748@microsoft.com...
> This is probably easy, but I have spent several hours trying to get it to 
> work with no luck.
>
> I'm just using the XmlSerializer class to write an XML file:
>
> XmlSerializer s = new XmlSerializer(typeof(myType));;
> XmlSerializerNamespaces n = new XmlSerializerNamespaces();
> n.Add(string.Empy, string.Empy);
> Stream fs = new FileStream(name, FileMode.Create);
> XmlTextWriter tw = new XmlTextWriter(fs, Encoding.UTF8);
> tw.Formatting = Formatting.None;
> s.Serialize(tw, myObject, n);
> tw.Close();
>
> Anyway, the above works almost to what I want, but it produces the 
> following XML file:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <q1:myObjElement1 xmlns:q1="myXSD.xsd">
>  <MyElement2>
>    <MyElement3>
>    </MyElement3>
>  </MyElement2>
> </q1:myObjeElement1>
>
> My problem is that I want to get rid of that "q1:" string, and just 
> serialize my object into XML.  What is the "q1:" string anyway, and why is 
> it there?
>
> I can get rid of the "q1:" string by changing the following attribute in 
> my code from:
>
> [System.Xml.Serialization.XmlRootAttribute(IsNullable = false, 
> Namespace="myXSD.xsd")];
>
> to:
>
> [System.Xml.Serialization.XmlRootAttribute(IsNullable = false)];
>
> However, if I do that, then I get:
> <?xml version="1.0" encoding="utf-8" ?>
> <myObjElement1>
>  <MyElement2>
>    <MyElement3>
>    </MyElement3>
>  </MyElement2>
> </myObjeElement1>
>
> The problem here is that I need the line:
>
> <myObjElement1>
>
> to really read:
>
> <myObjElement1 xmlns="myXSD.xsd">
>
>
> So in short:
> How can I get rid of the "q1:" string and keep the xmlns attribute in my 
> root element?
>
> Thank you.
>
>
>

Well, since I couldn't find an easy way to do this, I just added the 
attribute after I created the file:

XmlDocument d = new XmlDocument();
XmlElement e;
FileStream fs = new FileStream("myFile", FileMode.Open, FileMode.Read, 
FileMode.Read);
XmlTextReader tr = new XmlTextReader(fs);
d.Load(tr);
tr.Close();
e = d.DocumentElement;
e.SetAttribute("xmlns", "myNamespace");
d.Save("myFile");


0
6/3/2008 10:42:56 PM
"Tom" <johnthompson1@hotmail.com> wrote in message 
news:A9705A0F-A43A-411A-A012-1B8B97526748@microsoft.com...
> This is probably easy, but I have spent several hours trying to get it to 
> work with no luck.
>
> I'm just using the XmlSerializer class to write an XML file:
>
> XmlSerializer s = new XmlSerializer(typeof(myType));;
> XmlSerializerNamespaces n = new XmlSerializerNamespaces();
> n.Add(string.Empy, string.Empy);
> Stream fs = new FileStream(name, FileMode.Create);
> XmlTextWriter tw = new XmlTextWriter(fs, Encoding.UTF8);
> tw.Formatting = Formatting.None;
> s.Serialize(tw, myObject, n);
> tw.Close();
>
> Anyway, the above works almost to what I want, but it produces the 
> following XML file:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <q1:myObjElement1 xmlns:q1="myXSD.xsd">
>  <MyElement2>
>    <MyElement3>
>    </MyElement3>
>  </MyElement2>
> </q1:myObjeElement1>
>
> My problem is that I want to get rid of that "q1:" string, and just 
> serialize my object into XML.  What is the "q1:" string anyway, and why is 
> it there?
>
> I can get rid of the "q1:" string by changing the following attribute in 
> my code from:
>
> [System.Xml.Serialization.XmlRootAttribute(IsNullable = false, 
> Namespace="myXSD.xsd")];
>
> to:
>
> [System.Xml.Serialization.XmlRootAttribute(IsNullable = false)];
>
> However, if I do that, then I get:
> <?xml version="1.0" encoding="utf-8" ?>
> <myObjElement1>
>  <MyElement2>
>    <MyElement3>
>    </MyElement3>
>  </MyElement2>
> </myObjeElement1>
>
> The problem here is that I need the line:
>
> <myObjElement1>
>
> to really read:
>
> <myObjElement1 xmlns="myXSD.xsd">
>
>
> So in short:
> How can I get rid of the "q1:" string and keep the xmlns attribute in my 
> root element?
>
> Thank you.
>
>
It's not really an attribute, it's a namepace declaration.
It shouldn't matter to other processes whether it has a prefix or is a 
default namespace.
However:
   [XmlRoot(Namespace ="myXSD.xsd", ElementName = "myObjElement1")]
should get you <myObjElement1 xmlns="myXSD.xsd">

-- 

Joe Fawcett (MVP - XML)

http://joe.fawcett.name


0
6/4/2008 7:45:51 AM
Reply:

Similar Artilces:

Creating Custom Date format Q1-2009, etc.
Excel 2002 SP3 Win XP Pro SP2 Hi, How do I properly create a Darte format that will display: Q1-09 Q2-09 Q3-09 Q4-09 Q1-10 Q2-10 etc.? Q is of course for Quarter so Q1-09 is Jan to Mar 2009. Thanks! ="Q"&INT((MONTH(A1)+2)/3)&TEXT(A1,"-yy") -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "stef" <notvalid@nomail.nul> wrote in message news:%23CWOvqyyIHA.4492@TK2MSFTNGP02.phx.gbl... > Excel 2002 SP3 > Win XP Pro SP2 > > Hi, > > How do I properly create a Darte format that will dis...

q1 ???
This is probably easy, but I have spent several hours trying to get it to work with no luck. I'm just using the XmlSerializer class to write an XML file: XmlSerializer s = new XmlSerializer(typeof(myType));; XmlSerializerNamespaces n = new XmlSerializerNamespaces(); n.Add(string.Empy, string.Empy); Stream fs = new FileStream(name, FileMode.Create); XmlTextWriter tw = new XmlTextWriter(fs, Encoding.UTF8); tw.Formatting = Formatting.None; s.Serialize(tw, myObject, n); tw.Close(); Anyway, the above works almost to what I want, but it produces the following XML file: <?xml version=&qu...

VS Tools q1
VS Tools PDF says: When you create a new Visual Studio Tools for Microsoft Dynamics GP project, it will automatically contain a reference to the Application.Dynamics.dll application assembly. when I created new form, I didn't find anything similar to Application.Dynamics on refrences as below. [ Imports Microsoft.VisualBasic Imports System Imports System.Collections Imports System.Collections.Generic Imports Microsoft.Dexterity.Bridge Imports Microsoft.Dexterity.Applications Public Class GPAddIn Implements IDexterityAddIn ' IDexterityAddIn interface ...