Verifying node - InfoPath Dev
in

InfoPath Dev

Verifying node

Last post 02-12-2007 10:20 PM by elektrocad. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 02-12-2007 06:55 AM

    Verifying node

    Hello,

    I want to verify with a VB code if a node in an XML file exist or not.

    My code is:

    Dim nod As System.Xml.XmlNamespaceManager = New System.Xml.XmlNamespaceManager(m_xmld.NameTable)
    Dim Node As System.Xml.XmlNode = m_xmld.DocumentElement.SelectSingleNode("fTotal", nod)
    If Not m_xmld.SelectSingleNode("fTotal", nod) Is Nothing Then
    cell6.Value = m_xmld.GetElementsByTagName("my:fTotal").Item(0).InnerText
    row.Cells.Add(cell6)
    End If



    And this is not working, he never step into the IF.
    This code is in a cycle, and this source is reading some datas from XML files. The "my:fTotal" node exist in some files.
    A have to verify if exist this node or not because this line:
    cell6.Value = m_xmld.GetElementsByTagName("my:fTotal").Item(0).InnerText
    returns me an error is the node doesn't exist.

    Please help me.

    Best regards,
    eng. Nagy Ferenc
  • 02-12-2007 10:51 AM In reply to

    Hi eng. Nagy Ferenc, and welcome to the forums!

    I haven't worked with VBScript a lot, but you should be able to change your code to the below. I don't think you need a namespace manager when working with InfoPath.

    Dim Node As System.Xml.XmlNode = m_xmld.DocumentElement.SelectSingleNode("my:fTotal")
    If Not Node Is Nothing Then
    cell6.Value = Node.InnerText
    row.Cells.Add(cell6)
    End If

    Although I'm not sure what row.Cells.Add() does - is this an Excel smart doc? I'm not sure how much help we'll be able to offer with that.
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 02-12-2007 10:20 PM In reply to

    Hello,

    Thanks for your fast reply, but it's not working.
    I'm programming in Microsoft Visual Basic 2005 Express Edition and I'm working with XML files (create, modify, open, read ....).
    In the first line Dim Node As System.Xml.XmlNode = m_xmld.DocumentElement.SelectSingleNode("my:fTotalcuTVA") I've got the next message from the compilator:
    "Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function."
    And this is the reason because I was using the namespacemanager.
    I my code I haven't got this message, but it's not working.

    I was checking on the NET about "how to verify if a node exist or not in an XML file", but I found just similary with your code.

    Best regards,
    Feri
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.