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

XQuery FLWOR Queries in VB.Net

Status
Not open for further replies.

Meleagant

Programmer
Joined
Aug 31, 2001
Messages
166
Location
US
Is there any way to execute XQuery FLWOR queries from a VB.Net app? Basically I have a huge XML file that I need to validate. It consists basically of phone records (and no I am not working on some secret government project to see if you’re calling your mom often enough). The XML is basically:

Code:
<usage_details>
  <service_details servicenumber="1235551000">
    <usgitem callnumber="123456789" calldate="1/1/2006 9:00:00 AM" callstate="XX" callminutes="0.5" callcharges="0.025" location="Springfield"/>
    <usgitem callnumber="123456789" calldate="1/1/2006 9:00:00 AM" callstate="XX" callminutes="0.5" callcharges="0.025" location="Springfield"/>
    <usgitem callnumber="123456789" calldate="1/1/2006 9:00:00 AM" callstate="XX" callminutes="0.5" callcharges="0.025" location="Springfield"/>
    <usgitem callnumber="123456789" calldate="1/1/2006 9:00:00 AM" callstate="XX" callminutes="0.5" callcharges="0.025" location="Springfield"/>
  <service_subtotal qty="4" minutes="2" charges="0.1"/>
  </service_details>
  <service_details servicenumber="1235552000">
    <usgitem callnumber="123456789" calldate="1/1/2006 9:00:00 AM" callstate="XX" callminutes="0.5" callcharges="0.025" location="Springfield"/>
    <usgitem callnumber="123456789" calldate="1/1/2006 9:00:00 AM" callstate="XX" callminutes="0.5" callcharges="0.025" location="Springfield"/>
    <usgitem callnumber="123456789" calldate="1/1/2006 9:00:00 AM" callstate="XX" callminutes="0.5" callcharges="0.025" location="Springfield"/>
  <service_subtotal qty="3" minutes="1.5" charges="0.75"/>
  </service_details>
<usage_total qty="7" minutes="3.5" charges=".175"/>
</usage_details>

And what I want to return would be “Select ServiceNumber, Sum(callminutes), Sum(callcharges) From xmldocument Group By ServiceNumber” The result set would ‘hopefully’ look like this:

Code:
<ServiceNumber>1235551000
	<Sumcallminutes>4</Sumcallminutes>
	<sumcallcharges>.01</sumcallcharges>
</ServiceNumber>
<ServiceNumber>1235552000
	<Sumcallminutes>3</Sumcallminutes>
	<sumcallcharges>.075</sumcallcharges>
</ServiceNumber>

Very very simplified what I have tried so far is:
Code:
Passed into below Function
                FileName = objFile
                xmldoc = Nothing
                xmldoc = New System.Xml.XmlDocument()
                xmldoc.Load(FileName)
                xmlnav = xmldoc.CreateNavigator()
______________________________________________________________________

    Private Function UsageDetail(ByVal xmlDoc As System.Xml.XmlDocument, ByVal xmlnav As System.Xml.XPath.XPathNavigator, ByVal Path As String, ByVal CustID As String) As Boolean

        xmlnav.Evaluate("for $x in doc(" & Path & ")//usage_details/usage_type/service_details return count($x//usage_details/usage_type/service_details/usageitem)")

        x = xmlnav.InnerXml

	End Function

But I get an XML exception about a bad token. The Query that I am trying to pass is simpler that what I want. I figured if I could return SOMETHING I could then work from there. I don’t even know if this is possible. I will keep scouring the web for possible solutions.

Thanks

Journeyman -- The Order of the Seekers of Truth and Penitence
 
If anyone else is seeking answers to this question I did find this article:
I creates an add in where you can run XPath/XQuery expressions. I couldn't get it to work though, but I might be able to disect it to figure out how this person is executing FLWOR expressions.

Thanks to all who can help me.

Journeyman -- The Order of the Seekers of Truth and Penitence
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top