September 16, 2015 at 12:35 pm
I am parsing two XML files from my db, with Classic ASP (using MSXML2).
There are multiple children nodes which can vary in number, and I'm not sure how to approach parsing them. This occurs in the node "INTELLCONT_AUTH".
The first XML file presents a list of employees, while the second lists the 'intelligent content' (book) authored by one user, Susan Smith. There are additional collaborative authors listed in this book entry, in "INTELLCONT_AUTH".
How would I list each of those authors under this one book?
Thanks for any leads.
My desired output would resemble:
User =susan-smith
FirstName=Susan
MiddleName=L
LastName=Smith
Email=susan-smith@jam.net
STATUS=Submitted
TITLE=Home Recording, Part 1
INTELLCONT_AUTH id="106417006593"
FNAME=Nancy
MNAME>A.</MNAME>
LNAME>Smith</LNAME>
INTELLCONT_AUTH id="106417006595"
FNAME=Becky
MNAME=L
LNAME=Smith
STUDENT_LEVEL=MusD
INTELLCONT_AUTH id="106417006596"
FNAME=Arthur
LNAME=Smith
INTELLCONT_AUTH id="106417006597">
FNAME=Todd
LNAME=Smith
STUDENT_LEVEL=MusD
Here is the Classic ASP code I am using:
<%' setup the URL
baseUrl_1 = "XML_file_1.xml"
baseUrl_2 = "XML_file_2.xml"
username="*****"
password="*****"
Set http1 = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
Set http2 = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
Set myXML =Server.CreateObject("MSXML2.DOMdocument.3.0")
Set myXML2 =Server.CreateObject("MSXML2.DOMdocument.3.0")
myXML.Async=False
myXML2.Async=False
http1.open "GET", baseUrl_1, False, username, password
http2.open "GET", baseUrl_2, False, username, password
http1.setRequestHeader "PREFIX", "prefix"
http2.setRequestHeader "PREFIX", "prefix"
' send the HTTP data
http1.send()
http2.send()
if Not myXML2.load(http2.responseXML) then
response.write("no load myXML2")
end if
if Not myXML.load(http1.responseXML) then 'an Error loading XML
returnString = ""
Else 'parse the XML
Dim nodesURL
Set nodesUser=myXML.documentElement.selectNodes("//User")
Set nodesFirstName=myXML.documentElement.selectNodes("//FirstName")
Set nodesLastName=myXML.documentElement.selectNodes("//LastName")
Set nodesEMAIL=myXML.documentElement.selectNodes("//Email")
NumOfNodes_User = nodesUser.Length
response.write("NumOfNodes_User is... " & NumOfNodes_User & "
")
Set nodesRecord=myXML2.documentElement.selectNodes("//Record")
Set nodesIntellcont=myXML2.documentElement.selectNodes("//INTELLECTUAL_CONTENT")
Set nodesStatus=myXML2.documentElement.selectNodes("//STATUS")
Set nodesTitle=myXML2.documentElement.selectNodes("//TITLE")
Set nodesIntellcont_Auth=myXML2.documentElement.selectNodes("//INTELLCONT_AUTH")
Set nodesFaculty_Name=myXML2.documentElement.selectNodes("//FACULTY_NAME")
Set nodesFirst_Name=myXML2.documentElement.selectNodes("//FNAME")
Set nodesMiddle_Name=myXML2.documentElement.selectNodes("//MNAME")
Set nodesLast_Name=myXML2.documentElement.selectNodes("//LNAME")
Set nodesStudent_Level=myXML2.documentElement.selectNodes("//STUDENT_LEVEL")
NumOfNodes_Record = nodesRecord.Length
response.write("NumOfNodes_Record is... " & NumOfNodes_Record & "
")
NumOfNodes_Intellcont_Auth=nodesIntellcont_Auth.Length
response.write("NumOfNodes_Intellcont_Auth is... " & NumOfNodes_Intellcont_Auth & "
")
For i = 0 to NumOfNodes_User -1
Response.write(nodesLastName(i).text & ", " & nodesFirstName(i).text & " - <a href=""mailto:" & nodesEMAIL(i).text & " ""><font face=verdana size=2>" & nodesEMAIL(i).text & "</font></a>")
Username_att = nodesUser(i).getAttribute("username")
Username_List = Username_att
For y = 0 to (nodesRecord.length -1)
Rec_UserName=nodesRecord(y).getAttribute("username")
Rec_Title=nodesTitle(y).text
if Rec_UserName=Username_List then
response.write("
Rec_UserName is... " & Rec_UserName)
response.write("
Rec_Title is... " & Rec_Title & "
")
For a = 0 to (nodesIntellcont_Auth.length-1)
response.write(nodesIntellcont_Auth(a))
next
end if
Next
response.write("<HR>")
next
end if
%>
Here is XML_file_1.xml:
<Users>
<User username="susan-smith">
<FirstName>Susan</FirstName>
<MiddleName>L</MiddleName>
<LastName>Smith</LastName>
<Email>susan-smith@jam.net</Email>
</User>
<User username="jim-smith">
<FirstName>Jim</FirstName>
<MiddleName>L</MiddleName>
<LastName>Smith</LastName>
<Email>jim-smith@jam.net</Email>
</User>
<User username="veronica-smith">
<FirstName>Veronica</FirstName>
<MiddleName>L</MiddleName>
<LastName>Smith</LastName>
<Email>veronica-smith@jam.net</Email>
</User>
</Users>
Here is XML_file_2.xml:
<Record username="susan-smith">
<INTELLCONT>
<STATUS>Submitted</STATUS>
<TITLE>Home Recording, Part 1</TITLE>
<INTELLCONT_AUTH id="106417006593">
<FACULTY_NAME>1480892</FACULTY_NAME>
<FNAME>Nancy</FNAME>
<MNAME>A.</MNAME>
<LNAME>Smith</LNAME>
<STUDENT_LEVEL/>
</INTELLCONT_AUTH>
<INTELLCONT_AUTH id="106417006595">
<FACULTY_NAME>1480873</FACULTY_NAME>
<FNAME>Becky</FNAME>
<MNAME>L</MNAME>
<LNAME>Smith</LNAME>
<STUDENT_LEVEL>MusD</STUDENT_LEVEL>
</INTELLCONT_AUTH>
<INTELLCONT_AUTH id="106417006596">
<FACULTY_NAME/>
<FNAME>Arthur</FNAME>
<MNAME/>
<LNAME>Smith</LNAME>
<STUDENT_LEVEL/>
</INTELLCONT_AUTH>
<INTELLCONT_AUTH id="106417006597">
<FACULTY_NAME>1480896</FACULTY_NAME>
<FNAME>Todd</FNAME>
<MNAME/>
<LNAME>Smith</LNAME>
<STUDENT_LEVEL>MusD</STUDENT_LEVEL>
</INTELLCONT_AUTH>
</INTELLCONT>
</Record>
Viewing 0 posts
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy