Buongiorno a tutti
Da 5 giorni stò cercando di inserire delle righe in un file Xml senza successo.
Il file è questo allegato (ho cancellato qualche nodo perchè troppo lungo da pubblicare)
Creando la riga in questo modo:codice:<?xml version="1.0" encoding="utf-8"?> <?mso-application progid="Excel.Sheet"?> <ss:Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"> <ss:Worksheet ss:Name="Foglio1"> <ss:Table> ******RIGHE**** </ss:Table> </ss:Worksheet> </ss:Workbook>
questo è il risultato:codice:Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(XmlDoc.NameTable) nsmgr.AddNamespace("ss", "urn:schemas-microsoft-com:office:spreadsheet") Dim profile As XmlNode = XmlDoc.SelectSingleNode("//ss:Workbook/ss:Worksheet/ss:Table", nsmgr) Dim newElem As XmlElement = XmlDoc.CreateElement("Row","urn:schemas-microsoft-com:office:spreadsheet") newElem.SetAttribute("AutoFitHeight", "urn:schemas-microsoft-com:office:spreadsheet", "0") newElem.SetAttribute("Height", "urn:schemas-microsoft-com:office:spreadsheet", "15") profile.AppendChild(newElem)e dopo la xpath successiva non funziona e restituisce Nothingcodice:<Row ss:AutoFitHeight="0" ss:Height="15" />
se invece faccio:codice:profile = XmlDoc.SelectSingleNode("//ss:Workbook/ss:Worksheet/ss:Table/Row", nsmgr) If (profile Is Nothing) Then MsgBox("Errore") Exit Function End If
il risultato:codice:Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(XmlDoc.NameTable) nsmgr.AddNamespace("ss", "urn:schemas-microsoft-com:office:spreadsheet") Dim profile As XmlNode = XmlDoc.SelectSingleNode("//ss:Workbook/ss:Worksheet/ss:Table", nsmgr) (eliminato namespace) > Dim newElem As XmlElement = XmlDoc.CreateElement("Row") newElem.SetAttribute("AutoFitHeight", "urn:schemas-microsoft-com:office:spreadsheet", "0") newElem.SetAttribute("Height", "urn:schemas-microsoft-com:office:spreadsheet", "15") profile.AppendChild(newElem)
e non mi viene restituito Nothing.codice:<Row ss:AutoFitHeight="0" ss:Height="15" xmlns="" /> profile = XmlDoc.SelectSingleNode("//ss:Workbook/ss:Worksheet/ss:Table/Row", nsmgr) If (profile Is Nothing) Then MsgBox("Errore") Exit Function End If
Cosa non ho capito e stò sbagliando? di sicuro la xpath di sopra è errata, ma in cosa?

Rispondi quotando


