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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Parsing with ASP

Status
Not open for further replies.

dpimental

Programmer
Jul 23, 2002
535
US
All, I need to be able to parse the following

<enroll>
<personalInfo>
<name>john smith</name>
<email>jsmith@aol.com</email>
<position>loafer</position>
</personalInfo>
<busisness>
<companyName>ISIS Inc.</companyName>
</business>
</enroll>

I am writing an asp app to parse something like this. I need to be able to get a node by name, and either get the text value of that node, or another child node by name. And then get the text value of that child.

How do I do that? Do I use getElementsByTagName?

David Pimental
(US, Oh)
 
If I setup and xsl file, how do I set an asp (active server pages) variable to an xsl output?

David Pimental
(US, Oh)
 
It is something like this.
[tt]
<%
dim xmlfile,xslfile
xmlfile=server.mappath("abc.xml") 'maybe come from response object
xslfile=server.mappath("xyz.xsl") 'maybe come from response object

dim xmldom
set xmldom=server.createobject("msxml2.domdocument")
xmldom.validateOnParse=true
xmldom.async=false
xmldom.load xmlfile

dim xsldom
set xsldom=server.createobject("msxml2.domdocument")
xsldom.validateOnParse=true
xsldom.async=false
xsldom.load xslfile

dim sout
sout=xmldom.transformNode(xsldom)
response.write sout
%>
[/tt]
You've to beef it up with error control (.parseerror or err object itself).
 
How, do you set an asp variable to an xsl output value?c

if I had xml tags
<enroll>
<name>John Smith</name>
<age>21</age.
</enroll>

How do I set asp variables to name and age, like ...
<%
Dim myname, myage
myname = ?
myage = ?

%>

David Pimental
(US, Oh)
 
>If I setup and xsl file
In that case, you really meant "if"!

To get thing as simple as that, you mentioned getElementsByTagName. You can use it, can you not? or you don't know how?
[tt]
set onodelist=xmldom.getElementsByTagName("name")
myname=onodelist(0).text
'or alternative approach
myname=onodelist(0).childnodes(0).nodevalue
set onodelist=xmldom.getElementsByTagName("age")
myage=onodelist(0).text
'or alternative approach
myage=onodelist(0).childnodes(0).nodevalue
[/tt]
 
Yeah, I have that. Someone told me it might be better to use an xsl to parse the data.

I will go ahead and use that.

David

David Pimental
(US, Oh)
 
There are many ways to do it. The best way depends on what you want to do with it.

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top