xml dom parsing error - selectSingleNode gives 'undefined'

R

Rashida

Hi all!

I have written a function to fetch lebels from xml file for
cross-language interoperability. Please refer function code below.

I am invoking itfrom my asp page saying
<%=getValueForLabelNode(strLanguage,"English").toString()%>

It gives me an error 'Microsoft JScript runtime (0x800A138F)
'undefined' is null or not an object'

-----function code---
function getValueForLabelNode(lang, nodename)
{
try
{
// Name: getValueForLabelNode
// Input: Language code, Node name
// Output: Label Text
// Description: Fetches the Label Message for the language code
specified and the Label Name passed
// Author: IGSI - 2004

var LabelDoc= Server.CreateObject("MSXML2.DOMDocument");
var sPattern
var objLabels
var docurl


docurl = "../data/DebitMgrLabels.xml"

LabelDoc.async = false //asynchronous download not
permitted
LabelDoc.validateOnParse = true //Validates during parsing
LabelDoc.load (Server.MapPath(docurl)) //Loads the xml
resource at the passed docurl

// No parsing error
if (LabelDoc.parseError.errorCode == 0) {
//pattern to match the langauge node and corresponding Lable node
sPattern = "//language[@name='" + lang + "']//label[@name='" +
nodename + "']"

//ToDo. the below line returns undefined. Pls correct it.
objLabels = LabelDoc.selectSingleNode(sPattern);

//returning the text for the nodename passed
return objLabels.Text
}
}
catch(e)
{
return e.description;
}
}
 
M

Martin Honnen

Rashida said:
I have written a function to fetch lebels from xml file for
cross-language interoperability. Please refer function code below.

I am invoking itfrom my asp page saying
<%=getValueForLabelNode(strLanguage,"English").toString()%>

It gives me an error 'Microsoft JScript runtime (0x800A138F)
'undefined' is null or not an object'

-----function code---
function getValueForLabelNode(lang, nodename)
{
try
{
// Name: getValueForLabelNode
// Input: Language code, Node name
// Output: Label Text
// Description: Fetches the Label Message for the language code
specified and the Label Name passed
// Author: IGSI - 2004

var LabelDoc= Server.CreateObject("MSXML2.DOMDocument");
var sPattern
var objLabels
var docurl


docurl = "../data/DebitMgrLabels.xml"

LabelDoc.async = false //asynchronous download not
permitted
LabelDoc.validateOnParse = true //Validates during parsing
LabelDoc.load (Server.MapPath(docurl)) //Loads the xml
resource at the passed docurl

// No parsing error
if (LabelDoc.parseError.errorCode == 0) {

Try to set
LabelDoc.setProperty("SelectionLanguage", "XPath");
here before you call selectSingleNode.
//pattern to match the langauge node and corresponding Lable node
sPattern = "//language[@name='" + lang + "']//label[@name='" +
nodename + "']"

//ToDo. the below line returns undefined. Pls correct it.
objLabels = LabelDoc.selectSingleNode(sPattern);

You need to show us your XML input and the values of lang and nodename
so that we can check whether your XPath expression passed to
selectSingleNode should find a matching node or not.
 
R

Rashida

Martin Honnen said:
Rashida said:
I have written a function to fetch lebels from xml file for
cross-language interoperability. Please refer function code below.

I am invoking itfrom my asp page saying
<%=getValueForLabelNode(strLanguage,"English").toString()%>

It gives me an error 'Microsoft JScript runtime (0x800A138F)
'undefined' is null or not an object'

-----function code---
function getValueForLabelNode(lang, nodename)
{
try
{
// Name: getValueForLabelNode
// Input: Language code, Node name
// Output: Label Text
// Description: Fetches the Label Message for the language code
specified and the Label Name passed
// Author: IGSI - 2004

var LabelDoc= Server.CreateObject("MSXML2.DOMDocument");
var sPattern
var objLabels
var docurl


docurl = "../data/DebitMgrLabels.xml"

LabelDoc.async = false //asynchronous download not
permitted
LabelDoc.validateOnParse = true //Validates during parsing
LabelDoc.load (Server.MapPath(docurl)) //Loads the xml
resource at the passed docurl

// No parsing error
if (LabelDoc.parseError.errorCode == 0) {

Try to set
LabelDoc.setProperty("SelectionLanguage", "XPath");
here before you call selectSingleNode.
//pattern to match the langauge node and corresponding Lable node
sPattern = "//language[@name='" + lang + "']//label[@name='" +
nodename + "']"

//ToDo. the below line returns undefined. Pls correct it.
objLabels = LabelDoc.selectSingleNode(sPattern);

You need to show us your XML input and the values of lang and nodename
so that we can check whether your XPath expression passed to
selectSingleNode should find a matching node or not.


Thanks you! got it resolved.
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top