Xml Node exists

  • Thread starter Thread starter Gene Vangampelaere
  • Start date Start date
G

Gene Vangampelaere

Hello,

How can I check if a parameter (node) already exists in my xmldocument?
If it does not exists I have to add it

example:

If ExistsNode("SID") Then
'add the node
End If

I need some help for the "ExistsNode" function

<xml version="1.0">
<parameters>
<parameter>
<paramName>patnr</paramName>
<paramValue>00000</paramValue>
</parameter>
<parameter>
<paramName>SID</paramName>
<paramValue>00898798798798798D8d000</paramValue>
</parameter>
<parameter>
<paramName>GUID</paramName>
<paramValue>0090-JDI900000000-KKKDL000</paramValue>
</parameter>
</parameters>
</xml>
 
Gene said:
How can I check if a parameter (node) already exists in my xmldocument?
If it does not exists I have to add it

example:

If ExistsNode("SID") Then
'add the node
End If

I need some help for the "ExistsNode" function

<xml version="1.0">
<parameters>
<parameter>
<paramName>patnr</paramName>
<paramValue>00000</paramValue>
</parameter>
<parameter>
<paramName>SID</paramName>
<paramValue>00898798798798798D8d000</paramValue>
</parameter>
<parameter>
<paramName>GUID</paramName>
<paramValue>0090-JDI900000000-KKKDL000</paramValue>
</parameter>
</parameters>
</xml>

You can use XPath e.g.
If xmlDocument.SelectSingleNode("/parameters/parameter[@paramName =
'SID']") Is Nothing Then
' Add node
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top