SelectSingleNode returning undefined value:imsmanifest.xml

A

adam

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>
 
D

Dennis Myrén

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:blush:rganizations/default:blush:rganization/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 said:
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>
 
Top