我正在尝试生成此XML语句(减去格式和特定值):
<swatchcolor RGB="c5c5c5">
<sldcolorswatch:Optical
Ambient="0.520000"
Transparency="0.000000"
Diffuse="0.800000"
Specularity="1.000000"
Shininess="0.400000"
Emission="0.000000" />
</swatchcolor>
我正在使用这段代码:
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
不幸的是,我得到了以下带有不需要的xmlns子句的XML:
<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>
如何摆脱“xmlns”?我知道它就在那里,因为我正在使用WriteStartElement的第三个参数,但是当我使用双参数版本时,它会将“光学”一词移到不适当的位置,如下所示:
<swatchcolor RGB="c5c5c5">
<sldcolorswatch
Ambient=".520000"
Transparency=".000000"
Diffuse=".800000"
Specularity="1.000000"
Shininess=".400000"
Emission=".000000"
xmlns="Optical" />
</swatchcolor>
答案 0 :(得分:1)
我想你想要:
writer.WriteStartElement("sldcolorswatch", "Optical", "http://www.solidworks.com/sldcolorswatch");