xml - How can I find a node containing a sub-string? -


i able find nodes in xml file using following statement:

set user = objxmldoc.selectsinglenode("//user[@id = '" & id & "']") 

but xml files i'm reading being generated automatically , contain spaces after id. id attribute of user node might either of following:

<user id="e12345" name="dan smith"> <user id="e12345 " name="dan smith"> 

right appears variation in data. have no control on generation of files , cannot force trim @ end. have handle in code.

what's simplest way work around this? there kind of instr method use?

currently i'm coding around this, feels clumsy , handles exceptions when there 1 space:

set user = objxmldoc.selectsinglenode("//user[@id = '" & id & "']") if user nothing      set user = objxmldoc.selectsinglenode("//user[@id = '" & id & " ']") end if 

you can use contains():

set user = objxmldoc.selectsinglenode("//user[contains(@id,'" & id & "')]") 

or if spaces appear @ end of string can use starts-with():

set user = objxmldoc.selectsinglenode("//user[starts-with(@id,'" & id & "')]") 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -