how to validate XML node text using vbscript -
this xml file.
<parameter> <etpar_guix> <item> <pname>coas_1</pname> <ptyp>x</ptyp> <pdesc>generated table view</pdesc> <pindex>0001</pindex> <pgroup>gettab</pgroup> <xmlref_typ>t</xmlref_typ> <pstruc_typ>t</pstruc_typ> <pref_type>view</pref_type> <pref_name>coas</pref_name> <pdatlen>0000</pdatlen> <pintlen>000000</pintlen> <pdecimals>000000</pdecimals> <sort_lnr>0001</sort_lnr> <pref_name2>coas</pref_name2> <val_type>t</val_type> <tab_index>0</tab_index> </item> <item> <pname>i_order_number_from_table</pname> <ptyp>i</ptyp> <pdesc>generated table view</pdesc> <pindex>0001</pindex> <pgroup>i.01</pgroup> <xmlref_typ>t</xmlref_typ> <pstruc_typ>t</pstruc_typ> <pref_type>view</pref_type> <pref_name>coas</pref_name> <pdatlen>0000</pdatlen> <pintlen>000000</pintlen> <pdecimals>000000</pdecimals> <sort_lnr>0001</sort_lnr> <pref_name2>coas</pref_name2> <val_type>t</val_type> <tab_index>0</tab_index> </item> </etpar_guix> </parameter>
i want check whether xml node <pname>
starting letter "i" or not. if xml node <pname>
not starting letter "i" vb script should display error. tried vb script :
const xmldatafile = "d:\automation\imp\p.xml" set xmldoc = createobject("microsoft.xmldom") xmldoc.async = false xmldoc.load(xmldatafile) xmldoc.validateonparse = true if xmldoc.load(xmldatafile) msgbox "success loading xml file" else msgbox "error loading xml file" end if counter=0 set root = xmldoc.documentelement set items = root.childnodes each item in items mypname = xmldoc.getelementsbytagname("pname").item(counter).text if (left(mypname, 1) = "i") isvalid = true else isvalid=false end if next
this above vb script code check every single <pname>
letter si starting "i" or not. if none of xml node <pname>
letter not starting letter "i" vb script should display error. please me. thank in advance.
you need pre-set isvalid
false
outside loop , change value true
if find first match. change this:
for each item in items mypname = xmldoc.getelementsbytagname("pname").item(counter).text if (left(mypname, 1) = "i") isvalid = true else isvalid=false end if next
into this:
isvalid = false each item in items mypname = xmldoc.getelementsbytagname("pname").item(counter).text if left(mypname, 1) <> "i" isvalid = true exit end if next 'at point value of isvalid true if @ least 1 node text started 'with capital i. otherwise value false.
Comments
Post a Comment