473,387 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

SelectSingleNode returning undefined value:imsmanifest.xml

I tried so many ways to select the node but its not working, please help.
I want to research by the identifier in imsmanifest.xml file, the node could
be item or resource.

XmlDocument doc = new XmlDocument();
try
{
string node = Request.QueryString["node"]; //getting nodeid from
query string
doc.Load(Session["xmlFile"].ToString()); //load xml file from
session variable

//Create an XmlNamespaceManager for resolving namespaces.
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
//there are two namespaces not sure if I am doing it correctly
nsmgr.AddNamespace("imscp",
"urn:http://www.imsglobal.org/xsd/imscp_v1p1");
nsmgr.AddNamespace("imsmd",
"urn:http://www.imsglobal.org/xsd/imsmd_v1p2");

XmlNodeList nodes = doc.SelectNodes(//@identifier);
*******works***********

***************but SelectSingleNode() doesn't work**************************
----------------------------------------------------------------------------------------------------------------
XmlNode selectednode =
doc.DocumentElement.SelectSingleNode("manifest/organizations/organization/it
em[@identifier='+node+']", nsmgr);
-----------------------------------------------------------------------------------------------------------------
}
catch (Exception ex)
{
this.txtTitle.Text = ex.Message.ToString();
}

-----------------------------------------------imsmanifest.xml
file----------------------------------------
<?xml version="1.0"?>
<manifest identifier="MANIFEST01"
xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"
xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1 imscp_v1p1p3.xsd
http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">
<metadata>
<schema>IMS CONTENT</schema>
<schemaversion>1.1</schemaversion>
<imsmd:lom>
<imsmd:general>
<imsmd:title>
<imsmd:langstring xml:lang="en">Auditing 1 [AU1]</imsmd:langstring>
</imsmd:title>
</imsmd:general>
</imsmd:lom>
</metadata>
<organizations default="MANIFEST01_ORG1">
<organization identifier="MANIFEST01_ORG1">
<item identifier="MANIFEST01_ITEM3" isvisible="1" parameters=""
identifierref="MANIFEST01_RESOURCE1">
<title>Module 1: Introduction to auditing</title>
<item identifier="MANIFEST01_ITEM13"
identifierref="MANIFEST01_RESOURCE3" isvisible="1" parameters="">
<title>1.1 Nature of auditing</title>
</item>
<item identifier="MANIFEST01_ITEM14"
identifierref="MANIFEST01_RESOURCE6" isvisible="1" parameters="">
<title>1.2 External and internal auditing</title>
</item>
<item identifier="MANIFEST01_ITEM15"
identifierref="MANIFEST01_RESOURCE9" isvisible="1" parameters="">
<title>1.3 Assurance engagements</title>
</item>
</item>
</organization>
</organizations>
<resources>
<resource identifier="MANIFEST01_RESOURCE1" type="webcontent"
href="module01\mod01.overview.htm">
<file href="module01\mod01.overview.htm"/>
</resource>
<resource identifier="MANIFEST01_RESOURCE2" type="webcontent"
href="module01\topic01\lo1.01.htm">
<file href="module01\topic01\lo1.01.htm"/>
</resource>
<resource identifier="MANIFEST01_RESOURCE3" type="webcontent"
href="module01\topic01\mod01.1.htm">
<file href="module01\topic01\mod01.1.htm"/>
</resource>
</resources>
Nov 16 '05 #1
1 5591
First, since the document uses a default namespace,
you will need to associate a namespace prefix with the URL:
http://www.imsglobal.org/xsd/imscp_v1p1

To do that, just add a line using your XmlNamespaceManager.
Associate, for example, prefix "default" with that URL.
nsmgr.AddNamespace("default", "http://www.imsglobal.org/xsd/imscp_v1p1");

You were doing:
doc.DocumentElement.SelectSingleNode("manifest/organizations/organization/item[@identifier='+node+']",
nsmgr);
Since you run the SelectSingleNode in context of the root
element(doc.DocumentElement)
you will need to remove "manifest/" from the XPath. And you will also need
to
apply that namespace prefix you associated to the XPath.
So, it should look like:
default:organizations/default:organization/default:item[@identifier=' + node
+ ']"

However, i noticed there is actually only one <item> at that level in the
document,
which is the one of identifier 'MANIFEST01_ITEM3'.
So it will only work for that node.

So, what you should do(only thing you can do) if you do not know the level
of the <item>,
is performing a global search.
This XPath will find any <item> regardless of where in the document it is.
//default:item[@identifier=' + node + ']"

HTH.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"adam" <da**@dr.com> wrote in message
news:Or**************@TK2MSFTNGP11.phx.gbl...
I tried so many ways to select the node but its not working, please help.
I want to research by the identifier in imsmanifest.xml file, the node
could
be item or resource.

XmlDocument doc = new XmlDocument();
try
{
string node = Request.QueryString["node"]; //getting nodeid from
query string
doc.Load(Session["xmlFile"].ToString()); //load xml file
from
session variable

//Create an XmlNamespaceManager for resolving namespaces.
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
//there are two namespaces not sure if I am doing it correctly
nsmgr.AddNamespace("imscp",
"urn:http://www.imsglobal.org/xsd/imscp_v1p1");
nsmgr.AddNamespace("imsmd",
"urn:http://www.imsglobal.org/xsd/imsmd_v1p2");

XmlNodeList nodes = doc.SelectNodes(//@identifier);
*******works***********

***************but SelectSingleNode() doesn't
work**************************
----------------------------------------------------------------------------------------------------------------
XmlNode selectednode =
doc.DocumentElement.SelectSingleNode("manifest/organizations/organization/it
em[@identifier='+node+']", nsmgr);
-----------------------------------------------------------------------------------------------------------------
}
catch (Exception ex)
{
this.txtTitle.Text = ex.Message.ToString();
}

-----------------------------------------------imsmanifest.xml
file----------------------------------------
<?xml version="1.0"?>
<manifest identifier="MANIFEST01"
xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"
xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1
imscp_v1p1p3.xsd
http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">
<metadata>
<schema>IMS CONTENT</schema>
<schemaversion>1.1</schemaversion>
<imsmd:lom>
<imsmd:general>
<imsmd:title>
<imsmd:langstring xml:lang="en">Auditing 1 [AU1]</imsmd:langstring>
</imsmd:title>
</imsmd:general>
</imsmd:lom>
</metadata>
<organizations default="MANIFEST01_ORG1">
<organization identifier="MANIFEST01_ORG1">
<item identifier="MANIFEST01_ITEM3" isvisible="1" parameters=""
identifierref="MANIFEST01_RESOURCE1">
<title>Module 1: Introduction to auditing</title>
<item identifier="MANIFEST01_ITEM13"
identifierref="MANIFEST01_RESOURCE3" isvisible="1" parameters="">
<title>1.1 Nature of auditing</title>
</item>
<item identifier="MANIFEST01_ITEM14"
identifierref="MANIFEST01_RESOURCE6" isvisible="1" parameters="">
<title>1.2 External and internal auditing</title>
</item>
<item identifier="MANIFEST01_ITEM15"
identifierref="MANIFEST01_RESOURCE9" isvisible="1" parameters="">
<title>1.3 Assurance engagements</title>
</item>
</item>
</organization>
</organizations>
<resources>
<resource identifier="MANIFEST01_RESOURCE1" type="webcontent"
href="module01\mod01.overview.htm">
<file href="module01\mod01.overview.htm"/>
</resource>
<resource identifier="MANIFEST01_RESOURCE2" type="webcontent"
href="module01\topic01\lo1.01.htm">
<file href="module01\topic01\lo1.01.htm"/>
</resource>
<resource identifier="MANIFEST01_RESOURCE3" type="webcontent"
href="module01\topic01\mod01.1.htm">
<file href="module01\topic01\mod01.1.htm"/>
</resource>
</resources>

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: adam | last post by:
I tried so many ways to select the node but its not working, please help. I want to research by the identifier in imsmanifest.xml file, the node could be item or resource. XmlDocument doc = new...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.