Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Xml e Xpath

Hybrid View

  1. #1

    Xml e Xpath

    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?

  2. #2
    grazie per l'attenzione ho risolto
    avevo sbagliato (e si capiva) una cavolata assurda
    nella xpath avevo mancato ss:Row

    Roba da matti! guardato e riguardato e mica ci facevo caso che mancavano le ss: MALEDETTE


    ciao a tutti

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.