My XML comes in like this:
<Document type="ContentPage">
<Fields>
<Field name="FaqCategory" type="dropdown" title="Select Category:" index="FaqCategory" list="\Lists\FaqCategory" required="true">
Online Experience
</Field>
<Field name="FaqSubCategory" type="dropdown" title="Select Sub Category" list="\Lists\FaqSubCategory" required="true">
Using the site
</Field>
<Field name="FaqQuestion" type="text" title="Enter FAQ Question:" required="true">
How do I find articles on the site?
</Field>
<Field name="FaqAnswer" type="richtext" title="Enter FAQ Answer:" editorProfile="Advanced" required="true">
Answer to: How do I find articles on the site?
</Field>
</Fields>
<Placeholders />
<Indexes />
These are all in an array of XML objects, I need to sort through the array and set up (obviously) a FAQ section for this site. The problem I am having is that since this is not 1 xml document but a collection of xml documents, I am having a hard time sorting/separating by Main category > Sub category.
Here is where I am so far with the getting of the main categories:
Protected Sub getFaqData(ByVal DocArray() As CMSWS.CMSDocumentRecord)
Dim mainFaqCategoryItem As String = ""
Dim mainCategoryList As New List(Of String)
For Each Doc As CMSWS.CMSDocumentRecord In DocArray
xml.LoadXml(Doc.Xml)
Try
mainFaqCategoryItem = CType(xml.SelectSingleNode("//Fields/Field[@name='FaqCategory']").InnerText, String)
If Not mainCategoryList.Contains(mainFaqCategoryItem) Then
mainCategoryList.Add(mainFaqCategoryItem)
End If
Catch ex As Exception
Response.Write("ERROR getting the main category")
End Try
Next
For Each item In mainCategoryList
outputsubs(item, DocArray)
Next
End Sub
Here is the start of getting the sub categories and where I am stuck:
Protected Sub outputsubs(ByVal item As String, ByVal DocArray() As CMSWS.CMSDocumentRecord)
Dim subFaqCategoryItem As String = ""
Dim subcategoryList As New List(Of String)
'Add the main Category to the HTML output:
lblFaq.Text = lblFaq.Text & "<h1>" & item & "</h1>"
For Each Doc As CMSWS.CMSDocumentRecord In DocArray
xml.LoadXml(Doc.Xml)
Try
'If xml.SelectSingleNode("//Fields/Field[@name='FaqCategory']").InnerText = item Then
subFaqCategoryItem = CType(xml.SelectSingleNode("//Fields/Field[@name='FaqCategory']").InnerText, String)
If Not subcategoryList.Contains(subFaqCategoryItem) Then
subcategoryList.Add(subFaqCategoryItem)
End If
'End If
Catch ex As Exception
Response.Write("ERROR getting the main category")
End Try
Next
For Each subItem In subcategoryList
lblFaq.Text += "<h2><a name=""subCategory"" style=""text-decoration:none;""><span class=""FAQPlusMinus""> + </span>" & subItem & "</a></h2>"
Next
End Sub
My thinking is that I will need to set up for-each loops nested to about 3 levels to get this to work, but I can’t get my brain around it. Especially since it isn’t a single XML document.
Which works to display the main categories
I found the solution with trial and error, not sure if anyone else will be dealing with a similar situation but here is how I got it to work: