Xml Namespace Error

Hi everyone,

when using this

[code]Const kZero As String = “zero”

Dim bold As Boolean = True
Dim italic As Boolean = True

Dim xml As New XmlDocument
Dim rootNode, styleNode As XmlNode

rootNode = xml.AppendChild(xml.CreateElement(kZero, “style:style”))
rootNode.SetAttribute(“style:name”, “Name”) // working
rootNode.SetAttribute(“style:class”, “text”) // working
rootNode.SetAttribute(“style:parent-style-name”, “Standard”) // working

styleNode = rootNode.AppendChild(xml.CreateElement(kZero, “style:text-properties”))
If bold Then styleNode.SetAttribute(“fo:font-weight”, “bold”) // not working!
If italic Then styleNode.SetAttribute(“fo:font-style”, “italic”) // not working!![/code]
i’ll get the Error-Message “invalid namespace prefix”. Why the upper lines are working and why not the last two ones?

Because you have defined the name name space style for root not and not the name space fo so it’s unknown

Thx OK, and how to fix it? I need this result:

<style:text-properties xmlns:style="zero" fo:font-weight="bold" fo:font-style="italic"/>

write
rootNode.SetAttribute(“xmlns:fo”,“somedefinition”)
before using for the first time “of:” (before styleNode= is a good place)

PS you can use “somedefinition” or any string or more formally the uri of the formatting objects (fo stands for formatting object)