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)
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>
Creando la riga in questo modo:
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)
questo è il risultato:
codice:
<Row ss:AutoFitHeight="0" ss:Height="15" />
e dopo la xpath successiva non funziona e restituisce Nothing
codice:
profile = XmlDoc.SelectSingleNode("//ss:Workbook/ss:Worksheet/ss:Table/Row", nsmgr)
If (profile Is Nothing) Then
MsgBox("Errore")
Exit Function
End If
se invece faccio:
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)
il risultato:
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
e non mi viene restituito Nothing.
Cosa non ho capito e stò sbagliando? di sicuro la xpath di sopra è errata, ma in cosa?