tags:

views:

42

answers:

1

Hi. I'm trying to produce this XML statement (minus the formatting and specific values):

<swatchcolor RGB="c5c5c5">
  <sldcolorswatch:Optical 
    Ambient="0.520000" 
    Transparency="0.000000" 
    Diffuse="0.800000" 
    Specularity="1.000000" 
    Shininess="0.400000" 
    Emission="0.000000" />
</swatchcolor>

I'm using this chunk of code:

Public Sub ToXml(ByVal writer As XmlWriter)
    writer.WriteStartElement("swatchcolor")
    writer.WriteAttributeString("RGB", _rgb)
    writer.WriteStartElement("sldcolorswatch", "Optical", My.Resources.xmlns)
    writer.WriteAttributeString("Ambient", _ambient.ToString("####################.000000"))
    writer.WriteAttributeString("Transparency", _transparency.ToString("####################.000000"))
    writer.WriteAttributeString("Diffuse", _diffuse.ToString("####################.000000"))
    writer.WriteAttributeString("Specularity", _specularity.ToString("####################.000000"))
    writer.WriteAttributeString("Shininess", _shininess.ToString("####################.000000"))
    writer.WriteAttributeString("Emission", _emission.ToString("####################.000000"))
    writer.WriteEndElement()
    writer.WriteEndElement()
End Sub

Unfortunately, I get the following XML that has the unwanted xmlns clause:

<swatchcolor RGB="c5c5c5">
  <sldcolorswatch:Optical 
    Ambient=".520000" 
    Transparency=".000000" 
    Diffuse=".800000" 
    Specularity="1.000000" 
    Shininess=".400000" 
    Emission=".000000" 
    xmlns:sldcolorswatch="http://www.w3.org/2000/xmlns/" />
</swatchcolor>

How can I get rid of the "xmlns"? I know it's there because I'm using the third parameter of WriteStartElement, but when I use the two-parameter version, it moves the word "Optical" out of place, like this:

<swatchcolor RGB="c5c5c5">
  <sldcolorswatch 
    Ambient=".520000" 
    Transparency=".000000" 
    Diffuse=".800000" 
    Specularity="1.000000" 
    Shininess=".400000" 
    Emission=".000000" 
    xmlns="Optical" />
</swatchcolor>
+1  A: 

I think you want:

writer.WriteStartElement("sldcolorswatch", "Optical", "http://www.solidworks.com/sldcolorswatch");
steamer25
Just out of curiousity, how did you know I was working with SolidWorks?
scott8035
I Googled sldcolorswatch--the namespace for your Optical element.
steamer25