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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cdata section (XML)

Status
Not open for further replies.

josemauricio

Programmer
Sep 2, 2003
65
BR
Hi people,

is there any way to put a Cdata section inside a XML node in runtime?

Thanx for any help.

José Maurício.
 
Use the CreateCDataSection method on the XmlDocument object.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Hi chip, thank you for your replay.

let me explain the situation:

I have a main node called <erro>... inside this, I can have one or more node called <arq> and inside each of this nodes I should have other several nodes, wich one of them is called <conteudoArq>, wich its innerttext must be in a cdata section, because it contains some html code.

I already find a answer for my question by myself as follow: the node before <conteudoArq> is <dsErro>. So, I create a cdata section using CreateCDataSection e append it to a xmlelement object that I named <conteudoArq>. After that, I use the method InsertAfter to put <conteudoArq> after <dsErro>. There's all the code:

Dim file() As String = Directory.GetFiles(apppath & "Logs\Erro", "Erro_" & Year(Now) & mes & ".xml")

If UBound(file) <> -1 Then
xml.Load(apppath & "Logs\Erro\Erro_" & Year(Now) & mes & ".xml")

Dim nodeErro As XmlNode = xml.FirstChild
Dim nodeUltArq As XmlNode = nodeErro.LastChild
Dim id As Integer = nodeUltArq.Attributes("id").Value
Dim nodeArq As XmlNode = xml.CreateElement("arq")

Dim attrib As XmlAttribute = xml.CreateAttribute("nome")
attrib.Value = nomeArq
nodeArq.Attributes.Append(attrib)

Dim attribId As XmlAttribute = xml.CreateAttribute("id")
attribId.Value = id + 1
nodeArq.Attributes.Append(attribId)

nodeErro.AppendChild(nodeArq)

nodeArq.AppendChild(xml.CreateElement("servico"))
nodeArq("servico").InnerText = servico
nodeArq.AppendChild(xml.CreateElement("titulo"))
nodeArq("titulo").InnerText = titulo
nodeArq.AppendChild(xml.CreateElement("chave"))
nodeArq("chave").InnerText = chaves(0)
nodeArq.AppendChild(xml.CreateElement("senha"))
nodeArq("senha").InnerText = senha
nodeArq.AppendChild(xml.CreateElement("documento"))
nodeArq("documento").InnerText = documento
nodeArq.AppendChild(xml.CreateElement("formatacao"))
nodeArq("formatacao").InnerText = formatacao
nodeArq.AppendChild(xml.CreateElement("chavesAdicionais"))
For i = 1 To UBound(chaves)
Dim nodeChaves As XmlNode = xml.CreateElement("chave")
nodeChaves.InnerText = chaves(i)
nodeArq("chavesAdicionais").AppendChild(nodeChaves)
Next
nodeArq.AppendChild(xml.CreateElement("dsErro"))
nodeArq("dsErro").InnerText = erro

Dim cData As XmlCDataSection = xml.CreateCDataSection(sr.ReadToEnd)
Dim element As XmlElement = xml.CreateElement("conteudoArq")

element.AppendChild(cData)
nodeArq.InsertAfter(element, nodeArq("dsErro"))
End If

That way, I could solve my problem.

See you.
 
Glad you found an answer.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top