Last post Jan 04, 2011 01:01 PM by MountainMan
Dec 31, 2010 11:46 AM|MountainMan|LINK
<x-posted to Web Forms Data Controls)
I believe this may have something to do with xpath/xquery. I have learned how to do the xpath to slect the proper record but I don't know how to retrieve the data from the other attribute in the selected row.
but now how do I get the 'layout' from that row?
There does not seem to be a way to use a SELECT statement with an XML file.
<row id="1" description="descr 1" layout="layout 1" />
<row id="2" description="descr 2" layout="layout 2" />
<row id="3" description="descr 3" layout="layout 3" />
[SQL SELECT Statement]
SELECT layout FROM layout.xml WHERE description=myDescr
In other words, I know the "description" but I need the "layout"
Does anyone know how this could be done"
Dec 31, 2010 04:04 PM|Steelymar|LINK
Jan 03, 2011 11:49 AM|MountainMan|LINK
I don't seeem to be having a lot of luck.[VB]
Public Function GetLayoutString(ByVal myDescr As String) As String
Dim strXpath As String = "/layout/row[@description=" & myDescr & "]/@layout"
Dim xpathDoc = New XPathDocument("~/App_Data/Layout.xml")
Dim xpathNav As System.Xml.XPath.XPathNavigator = xpathDoc.CreateNavigator()
Dim query As XPathExpression = xpathNav.Compile(strXpath)
Jan 03, 2011 01:58 PM|Steelymar|LINK
add quotation marks:
Dim strXpath As String = "/layout/row[@description='" & myDescr & "']/@layout"
Jan 03, 2011 06:09 PM|MountainMan|LINK
I'm really learning to hate XML.
You were right abouth the quotes but it's still not working. I don't know what to do with the query or even if I should be using Compile.
Jan 04, 2011 01:01 PM|MountainMan|LINK
For anyone else who stumbles across this threa, here's the working code:
Private Function GetLayoutString(ByVal MyDescr As String) As String
Dim strXpath As String = "/layout/row[@Description='" & MyDescr & "']/@LayoutString"
Dim xpathDoc = New XPathDocument(Server.MapPath("~/App_Data/Layout.xml"))
Dim nav As System.Xml.XPath.XPathNavigator = xpathDoc.CreateNavigator()
Dim NodeIter As XPathNodeIterator = nav.Select(strXpath)
Dim LS As String = NodeIter.Current.Value.ToString()
One final mistake I made that I had to clean up:
When I created the sample XML file for this thread, I used 'layout' as the row 'layout' attribute. In my actual XML file, that attribute is called 'LayoutString' Stupid, stupid me.