[
Lists Home |
Date Index |
Thread Index
]
>> 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@microsoft.com> wrote:
> > -----Original Message-----
> > From: John Sands [mailto:wonkowatson@yahoo.com]
> > Sent: Sunday, April 07, 2002 8:46 PM
> > To: xml-dev@lists.xml.org
> > Subject: [xml-dev] 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/
|