Solved

Filter xml file

Posted on 2008-06-23
8
334 Views
Last Modified: 2013-11-11
Hi Experts,

I have a xml file that is constructed by using a view on an SQL table, the xml file is used to supply mapping co-ordinates,
unfortunately I am unable to filter this view at source. How could I Filter this xml by the Title element
and use this filter to write another xml file with the same elements.



<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:georss="http://www.georss.org/georss/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
  <channel>
    <item>
      <title>XTLM500</title>
      <type>1</type>
      <description>&lt;img src= Images/Small.jpg&gt;&lt;br&gt United Kingdom&lt;br&gt;&lt;strong&gt;Vehicle Type</description>
      <icon>Images/truck-small-picture5.gif</icon>
      <ordnum>YourOrderNum</ordnum>
      <geo:lat>51.6922833333333</geo:lat>
      <geo:long>-1.87274666666667</geo:long>
    </item>
  </channel>
</rss>

Regards,
JoeBo
0
Comment
Question by:JoeBo747
  • 3
  • 2
8 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 21849124
I don't quite get the context for the question.   Are you saying that you have a DataSet that is constructed and filled from an XML file, and you want to create a RowFilter for a DataView?
0
 
LVL 1

Author Comment

by:JoeBo747
ID: 21853090
Hi TheLearnedOnei,
Thanks for the reply I have an XML file that plots positions on virtual earth the XML file is created using the a dblm datasource (monitoring)  is created using a view on  sql server 2005. This view has some fixed delimiters but I also wish to further limit the data source using a variable that must be supplied at runtime. The view does not allow this to happen so I need to either find a method that will achieve this or filter the resulting XML file a rebuild an xml file with the required records. Can you suggest a fix? I have reproduced the code that plots the position.

regards,

JoeBo

  Try

            Dim db As New MonitoringDataContext

            Dim geoRSS = _

                 <rss xmlns:georss="http://www.georss.org/georss/">

                     <channel>

                         <%= From Monitoring In db.MonViews _

                             Let desc = "<img src= Images/SmallGBA.jpg" _

                             & "><br>" & Monitoring.Location _

                             & "<br><strong>Vehicle Type" _

                             Select <item>

                                        <title><%= Monitoring.OrdNum %></title>

                                        <type><%= Monitoring.TripType %></type>

                                        <description><%= desc %></description>

                                        <icon><%= Monitoring.VehDescription %></icon>

                                        <ordnum><%= Monitoring.OrdNum %></ordnum>

                                        <geo:lat><%= Monitoring.Latitude %></geo:lat>

                                        <geo:long><%= Monitoring.Longitude %></geo:long>

                                    </item> %>

                     </channel>

                 </rss>

            geoRSS.Save(Server.MapPath("Monitoring.xml"))

            'Me.TextBox1.Text = (geoRSS.ToString)

            'LoadTree()

            If geoRSS...<item>.Count > 0 Then

                Session("georss") = geoRSS
 

                Me.body.Attributes.Add("onload", String.Format("GetMap()"))

            Else

                'Me.lblStatus.Visible = True

                Session("georss") = <rss></rss>

            End If

        Catch ex As Exception

            MsgBox(Err.Description)

        Finally

            If Not Page.IsPostBack Then LoadTree()

        End Try

Open in new window

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 21854094
Are you talking about version 3.5, and LINQ?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Author Comment

by:JoeBo747
ID: 21856891
Hi TheLearnedOne,

Sorry about the delay I have been out. Yes I am using version 3.5 and LINQ!

Regards,
JoeBo
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 21880022
I am sorry, but I can't help you with that, yet.
0
 
LVL 4

Accepted Solution

by:
ad5qa earned 500 total points
ID: 21953852
Try this, I am a begineer at Linq and there may be a better way. With this you can add a where clause also. Add your xml description and whatever before and after and you can stream to a file. Could be your starting point.




 XDocument xmlDoc = XDocument.Load("http://www.georss.org/georss/"); //Replace with URL

        var q = from c in xmlDoc.Descendants("item")
 

                select "<title>" + (string)c.Element("title") + "</title>" +

                       "<type>" + (string)c.Element("type") + "</type>" +

                       "<description>" + (string)c.Element("description") + "</description>" +

                       "<icon>" + (string)c.Element("icon") + "</icon>" +

                       "<ordnum>" + (string)c.Element("ordnum") + "</ordnum>" +

                       "<geo:lat>" + (string)c.Element("geo:lat") + "</geo:lat>" +

                       "<geo:lon>" + (string)c.Element("geo:lon") + "</geo:lon>";

                

        foreach (string name in q)

        {

            Console.WriteLine(name);

        }

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Not showing page correctly 3 29
Error on Add method 1 37
What .NET URL re-routing tool did I use? 2 36
Allow User To Arrange Columns At Datagridview 3 19
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now