[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: XPath problem with selectSingleNode in MSXML4
>> getAttribute returns a string while selectSingleNode returns >> an object Yes! Got it now: var href = xmldoc.selectSingleNode("/config/link[@default]/@href").value; Thanks. --- Dare Obasanjo <dareo@m...> wrote: > > -----Original Message----- > > From: John Sands [mailto:wonkowatson@y...] > > Sent: Sunday, April 07, 2002 8:46 PM > > To: xml-dev@l... > > Subject: XPath problem with selectSingleNode in MSXML4 > > > > > > I have a file called config.xml like this: > > > > <?xml version="1.0"?> > > <config> > > <link href="tree.asp"/> > > <link href="search.asp" default="true" /> > > </config> > > > > This Javascript ASP code finds the href with the > > "default=true" attribute: > > > > var xmldoc = new ActiveXObject("MSXML2.DOMDocument.4.0"); > > xmldoc.async = false; xmldoc.load(Server.MapPath("config.xml")); > > xmldoc.setProperty("SelectionLanguage", "XPath"); > > var defaultpage = xmldoc.selectSingleNode("/config/link[@default]"); > > var href = defaultpage.getAttribute("href"); > > > > My question is, why doesn't this code find it as well? > > > > var xmldoc = new ActiveXObject("MSXML2.DOMDocument.4.0"); > > xmldoc.async = false; xmldoc.load(Server.MapPath("config.xml")); > > xmldoc.setProperty("SelectionLanguage", "XPath"); > > var href = xmldoc.selectSingleNode("/config/link[@default]/@href"); > > > > The latter code does find it as well. The following code works fine for > me > > var xmldoc = new ActiveXObject("MSXML2.DOMDocument.4.0"); > xmldoc.async = false; > xmldoc.loadXML("<config><link href=\"tree.asp\"/><link > href=\"search.asp\" default=\"true\" /></config>"); > WScript.Echo(xmldoc.xml); > xmldoc.setProperty("SelectionLanguage", "XPath"); > var defaultpage = xmldoc.selectSingleNode("/config/link[@default]"); > var href = defaultpage.getAttribute("href"); > WScript.Echo("1: " + href); > href = xmldoc.selectSingleNode("/config/link[@default]/@href"); > WScript.Echo("2: " + href.value); > > when executed using Windows scripting host. The difference in behavior > is because getAttribute returns a string while selectSingleNode returns > an object. > > Hope this helps. > > PS: Ignore my prior offlist email, this is NOT a bug. > > -- > PITHY WORDS OF WISDOM > A journey of a thousand miles begins with a cash advance. > > This posting is provided "AS IS" with no warranties, and confers no > rights. > You assume all risk for your use. (c) 2002 Microsoft Corporation. All > rights reserved. __________________________________________________ Do You Yahoo!? Yahoo! Tax Center - online filing with TurboTax http://taxes.yahoo.com/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|