Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Parse

Status
Not open for further replies.

guitardave78

Programmer
Sep 5, 2001
1,294
GB
Inthe following XML file how would I get the value of the node //imsmd:general//imsmd:title//imsmd:langstring//

Code:
<manifest xmlns="[URL unfurl="true"]http://www.imsglobal.org/xsd/imscp_v1p1"[/URL] xmlns:imsmd="[URL unfurl="true"]http://www.imsproject.org/xsd/ims_md_rootv1p1"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xsi:schemaLocation="[URL unfurl="true"]http://www.imsglobal.org/xsd/imscp_v1p1[/URL]
[URL unfurl="true"]http://www.imsglobal.org/xsd/imscp_v1p1.xsd[/URL]
[URL unfurl="true"]http://www.imsproject.org/xsd/ims_md_rootv1p1[/URL]
[URL unfurl="true"]http://www.imsglobal.org/xsd/ims_md_rootv1p1.xsd"[/URL] identifier="man_F8EEBA77-2446-45C5-807C-C9F076A5758F">
	<metadata>
	<imsmd:general>
	  <imsmd:title>
		<imsmd:langstring>
	Writing a CV - Writing a CV
		</imsmd:langstring>
	  </imsmd:title>
	</imsmd:general>
	</metadata>
</manifest>

}...the bane of my life!
 
I wrote a JS function a while back that I use to get XML data, but can't find it right now. It takes the tag as the argument (without the pointy brackets) along with the XML data and returns the character string inside. It wasn't difficult to write, was something like:
Code:
function getXMLcontents(tagname, xdata)
{
var opentag = '<' + tagname + '>';
var closetag = '</' + tagname + '>';
var contents = xdata.substr(xdata.indexOf(opentag) + opentag.length);
contents = contexts.substr(0, contents.indexOf(closetag));
return contents;
}

That's not tested, so it might need touched up.

Using the function would be something like:

Code:
xmldata = ''; //assign the XML data to a string
var value = getXMLcontents('imsmd:general', xmldata);
if (value.length > 0)
  {
  value = getXMLcontents('imsmd:title', value);
  }
if (value.length > 0)
  {
  value = getXMLcontents('imsmd:langstring', value);
  }

Lee
 
I am converting an asp function set to javascript

so for instance converting this
Code:
default = (xmlDocument.selectNodes("//organizations//")(0).getAttribute("default"))
	set items = xmlDocument.selectNodes("//organizations//organization[@identifier='"&default&"']//item//")
	for each item in items
		If response.IsClientConnected=true then
			if isObj(item.selectSingleNode("title"), "") <> "" then
				call getNav(orig,path,item.getAttribute("identifierref"),isObj(item.selectSingleNode("title"), ""))
			end if
		else
			response.End()
		end if
	next


}...the bane of my life!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top