Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XmlTextReader, Attribute of ElementString? 1

Status
Not open for further replies.

mrmovie

Technical User
Oct 2, 2002
3,094
GB
Hi All, I am trying to write out the following:

<environments>
<environment name="CB001" description="cluster build 001">
<envvariable name="ROLE.CLUSTERNODE1">GB8644TD3T</envvariable>
</environment>
</environments>

using the XmlTextReader

this is fine:
xmlTextWriter.WriteStartElement("environments")
xmlTextWriter.WriteStartElement("environment")
xmlTextWriter.WriteAttributeString("name", strEnvironmentName)
xmlTextWriter.WriteAttributeString("description", strEnvironmentName & " build")

but i get stuck with the element string entry
'this doesnt allow to assign a element value, or at least i cant figure out how to
xmlTextWriter.WriteStartElement("envvariable")
xmlTextWriter.WriteAttributeString("name", "ROLE.CLUSTERNODE")

'this errors when trying to set an AttributeString
xmlTextWriter.WriteElementString("envvariable", "GB8644TD3T")
xmlTextWriter.WriteAttributeString("name", "ROLE.CLUSTERNODE")

I can write it out using WriteRaw but i figure it is cheating (and seems to stuff up my EndElement indenting

'xmlTextWriter.WriteRaw(vbCrLf)
'xmlTextWriter.WriteRaw(" <envvariable name=" & Chr(34) & "MS.HELLO1" & Chr(34) & ">" & "testXXX" & "</envvariable>")
'xmlTextWriter.WriteRaw(vbCrLf)
 
Maybe this?
[tt]
'this doesnt allow to assign a element value, or at least i cant figure out how to
xmlTextWriter.WriteStartElement("envvariable")
xmlTextWriter.WriteAttributeString("name", "ROLE.CLUSTERNODE")
xmlTextWriter.WriteString("GB8644TD3T")
xmlTextWriter.WriteEndElement()
[/tt]
ref
 
thanks for the post tsuji.,
i may try that out. i did however get bored with xmlTextWriter and have gone for xmlDocument and something along the lines of:

For Each strKey In dicTempHashTable.Keys
If InStr(strKey, ".") Then 'this is important to document!!!!!! DOCUMENT
Dim xmlEnvVar As XmlElement = xmlEnvironment.AppendChild(xmlDoc.CreateElement("envvariable"))
xmlEnvVar.InnerText = dicTempHashTable.Item(strKey)
xmlEnvVar.Attributes.Append(xmlDoc.CreateAttribute("name"))
xmlEnvVar.Attributes("name").Value = Replace(strKey, "%", "").ToUpper
End If
Next

I have also used the Serialize and Deserialize stuff for some of my classes which I have found to be 'cool'

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top