How to insert and query nodes?

Hi all,

I need to use XML to store some log data and then query that data.  I'm 
struggling with the right terminology, which is hindering my ability to 
successfully search for a solution.  Thanks in advance for your help!

Two questions:
1.  In VB.NET, how can I append new "Log" record to a "Site" record?
2.  How can I query all of "Log" records in a single "Site" for an average 
"ResponseTime"?

------------------------------

<?xml version="1.0" standalone="yes" ?> 
<Sites>
  <Site Host="www.mysite1.com" IP="1.1.1.1" /> 
  <Site Host="www.mysite2.com" IP="1.1.1.2" /> 
  <Site Host="www.mysite3.com" IP="1.1.1.3">
    <Log Time="1/1/2008 12:00:00 AM" Status="Success" ResponseTime="10" /> 
    <Log Time="1/1/2008 12:00:01 AM" Status="Failure" ResponseTime="10" /> 
  </Site>
  <Site Host="www.mysite4.com" IP="1.1.1.4">
    <Log Time="1/1/2008 12:00:00 AM" Status="Success" ResponseTime="10" /> 
    <Log Time="1/1/2008 12:00:01 AM" Status="Failure" ResponseTime="10" /> 
  </Site>
</Sites>

0
JasonT80 (3)
10/7/2008 12:42:01 PM
dotnet.xml 7266 articles. 0 followers. Follow

4 Replies
713 Views

Similar Articles

[PageSpeed] 23

JasonT80 wrote:

> Two questions:
> 1.  In VB.NET, how can I append new "Log" record to a "Site" record?

With .NET 1.x, 2.0 and 3.0 you would use System.Xml.XmlDocument e.g.
   Dim doc As New XmlDocument()
   doc.Load("file.xml")
   Dim log As XmlElement = doc.CreateElement("Log")
   log.SetAttribute("Time", "...")
   log.SetAttribute("Status", "...")
   doc.SelectSingleNode("Sites/Site[@Host = 
'www.mysite1.com']").AppendChild(log)
   doc.Save("file.xml")

With .NET 3.5 you would use LINQ to XML. Let us know whether you use 
that version and need sample code.

> 2.  How can I query all of "Log" records in a single "Site" for an average 
> "ResponseTime"?

A solutuon again depends on whether you can use LINQ to XML so please 
let us know which version of the .NET framework you use/want to use.

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
10/7/2008 1:00:19 PM
The environment has only .NET 2.0.  Thanks for the help!

-- 
Jasont80


"Martin Honnen" wrote:

> JasonT80 wrote:
> 
> > Two questions:
> > 1.  In VB.NET, how can I append new "Log" record to a "Site" record?
> 
> With .NET 1.x, 2.0 and 3.0 you would use System.Xml.XmlDocument e.g.
>    Dim doc As New XmlDocument()
>    doc.Load("file.xml")
>    Dim log As XmlElement = doc.CreateElement("Log")
>    log.SetAttribute("Time", "...")
>    log.SetAttribute("Status", "...")
>    doc.SelectSingleNode("Sites/Site[@Host = 
> 'www.mysite1.com']").AppendChild(log)
>    doc.Save("file.xml")
> 
> With .NET 3.5 you would use LINQ to XML. Let us know whether you use 
> that version and need sample code.
> 
> > 2.  How can I query all of "Log" records in a single "Site" for an average 
> > "ResponseTime"?
> 
> A solutuon again depends on whether you can use LINQ to XML so please 
> let us know which version of the .NET framework you use/want to use.
> 
> -- 
> 
> 	Martin Honnen --- MVP XML
> 	http://JavaScript.FAQTs.com/
> 
0
JasonT80 (3)
10/7/2008 7:13:00 PM
JasonT80 wrote:

> 2.  How can I query all of "Log" records in a single "Site" for an average 
> "ResponseTime"?
> 
> ------------------------------
> 
> <?xml version="1.0" standalone="yes" ?> 
> <Sites>
>   <Site Host="www.mysite1.com" IP="1.1.1.1" /> 
>   <Site Host="www.mysite2.com" IP="1.1.1.2" /> 
>   <Site Host="www.mysite3.com" IP="1.1.1.3">
>     <Log Time="1/1/2008 12:00:00 AM" Status="Success" ResponseTime="10" /> 
>     <Log Time="1/1/2008 12:00:01 AM" Status="Failure" ResponseTime="10" /> 
>   </Site>
>   <Site Host="www.mysite4.com" IP="1.1.1.4">
>     <Log Time="1/1/2008 12:00:00 AM" Status="Success" ResponseTime="10" /> 
>     <Log Time="1/1/2008 12:00:01 AM" Status="Failure" ResponseTime="10" /> 
>   </Site>
> </Sites>

Here is an example that computes the average ResponseTime for those Site 
elements that have at least on Log child element with a ResponseTime 
attribute:

Imports System
Imports System.Xml.XPath


Module Module1

     Sub Main()
         Dim doc As New XPathDocument("..\..\XMLFile1.xml")
         For Each site As XPathNavigator In 
doc.CreateNavigator().Select("Sites/Site[Log/@ResponseTime]")
             ComputeAverage(site)
         Next
     End Sub

     Sub ComputeAverage(ByVal site As XPathNavigator)
         Console.WriteLine(site.Evaluate("sum(Log/@ResponseTime) div 
count(Log/@ResponseTime)"))
     End Sub

End Module


So with XPath the solution is to evaluate the XPath expression
   sum(Log/@ResponseTime) div count(Log/@ResponseTime)
with the Site element as the context node.



-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
10/8/2008 11:54:43 AM
That worked.  THANKS!

-- 
Jasont80


"Martin Honnen" wrote:

> JasonT80 wrote:
> 
> > 2.  How can I query all of "Log" records in a single "Site" for an average 
> > "ResponseTime"?
> > 
> > ------------------------------
> > 
> > <?xml version="1.0" standalone="yes" ?> 
> > <Sites>
> >   <Site Host="www.mysite1.com" IP="1.1.1.1" /> 
> >   <Site Host="www.mysite2.com" IP="1.1.1.2" /> 
> >   <Site Host="www.mysite3.com" IP="1.1.1.3">
> >     <Log Time="1/1/2008 12:00:00 AM" Status="Success" ResponseTime="10" /> 
> >     <Log Time="1/1/2008 12:00:01 AM" Status="Failure" ResponseTime="10" /> 
> >   </Site>
> >   <Site Host="www.mysite4.com" IP="1.1.1.4">
> >     <Log Time="1/1/2008 12:00:00 AM" Status="Success" ResponseTime="10" /> 
> >     <Log Time="1/1/2008 12:00:01 AM" Status="Failure" ResponseTime="10" /> 
> >   </Site>
> > </Sites>
> 
> Here is an example that computes the average ResponseTime for those Site 
> elements that have at least on Log child element with a ResponseTime 
> attribute:
> 
> Imports System
> Imports System.Xml.XPath
> 
> 
> Module Module1
> 
>      Sub Main()
>          Dim doc As New XPathDocument("..\..\XMLFile1.xml")
>          For Each site As XPathNavigator In 
> doc.CreateNavigator().Select("Sites/Site[Log/@ResponseTime]")
>              ComputeAverage(site)
>          Next
>      End Sub
> 
>      Sub ComputeAverage(ByVal site As XPathNavigator)
>          Console.WriteLine(site.Evaluate("sum(Log/@ResponseTime) div 
> count(Log/@ResponseTime)"))
>      End Sub
> 
> End Module
> 
> 
> So with XPath the solution is to evaluate the XPath expression
>    sum(Log/@ResponseTime) div count(Log/@ResponseTime)
> with the Site element as the context node.
> 
> 
> 
> -- 
> 
> 	Martin Honnen --- MVP XML
> 	http://JavaScript.FAQTs.com/
> 
0
JasonT80 (3)
10/14/2008 11:33:01 AM
Reply:

Similar Artilces:

query Form 12-06-07
At work, we use a large database. In it, there are 400 records for personnel. The table this is based on has about 40 fields. Currently, whenever we need to print out a report with different queries, I need to make the query from scratch. Although not hard, I don't want to keep doing this as my boss thinks of new things. So what I would like to do is create one form. This form will have 10 drop down menus. The first drop down will be the field the query will sort by. After that, each option they choose will be a field the query will pull. For example: Command: Field5 Command: Fie...

Matching Zip coded in a Query
I have query that joins two tables using the Zip Codes (only show the records where the Zip codes match). The problem is that in one table, the listing of zip codes, it is 5 digit zip codes. In the main table some of the zip codes are 5+4 zip codes. My current query leave out the 5+4 Zip codes. I want all the records as long as the 5 digit zip codes matches. I quess I could delete the - and the last 4 digits on the main table, but it would be nice to retain the whole zip codes. Is there a way to do this? Thanks!!!!! Use Left(MainTableZipCodeField,5) to compare to the original ...

removing blank fields in a query
I need to build a table using a old database. the field I want has some data in them but can also have blanks. I do not wan the fields with blanks how do I accomplish this. -- Les >>I do not wan the fields with blanks Just omit that field. Or do you not want records that have blank fields? Use criteria of Is Not Null on the field. -- KARL DEWEY Build a little - Test a little "Les" wrote: > I need to build a table using a old database. the field I want has some data > in them but can also have blanks. I do not wan the fields with blanks how ...

How do I insert Roman Numerals?
New to Word 2007 would someone please explain to me how to insert Roman Numerlas in my document? "ckj" <ckj@discussions.microsoft.com> wrote in message news:6CF0C580-BA6E-463D-B4FD-E6A6FDD9E814@microsoft.com... > New to Word 2007 would someone please explain to me how to insert Roman > Numerlas in my document? Just type them... I II III IV V VI VII VIII IX X XI etc etc. Type a number e.g. 21, select it and run the following macro Dim oRng As Range Set oRng = Selection.Range oRng.Fields.Add oRng, 34, oRng.Text & " \*Roman"...

Insert trigger
Looking for some advice on SQL 2005. I have a table that will usually be populated by an SSIS package. I want to set the "loaddate" column to the current time after a record is inserted. Should i do this via trigger or should i just build a step in the SSIS package to update the column after the file loads? If trigger is the way to go, what is the syntax to create the after insert trigger? Thanks in advance. You can create a default constraint on the table set to CURRENT_TIMESTAMP. That will handle the automatic date assignment without any need for coding. -...

inserting hrs and minutes
I have a cell in my time card that displays total weekly time -ex- "40:15" is there a way to make it more like this...40hrs,15mins -- Message posted from http://www.ExcelForum.com Use a custom format hh"hrs",mm"mins" -- Regards, Peo Sjoblom "-Brian-H- >" <<Brian-H-.110wgs@excelforum-nospam.com> wrote in message news:Brian-H-.110wgs@excelforum-nospam.com... > I have a cell in my time card that displays total weekly time -ex- > "40:15" is there a way to make it more like this...40hrs,15mins ? > > > ...

Help with InStr in a query
I have values like "2010 WW14" and "2010 WW7" in a query and I'm trying to grab the number part to the right of "WW". It will always be a 1 or 2 digit number and I always want the format to be a number. I'm currently using Left([WorkWeek2],(InStr(1,[WorkWeek2],"ww")-1)) to grab the 4-digit year to the left of "WW", but I can't figure out how to alter it for what I need above. Any suggestions? Thanks! Try: mid(WorkWeek2,instr(WorkWeek2,'ww')+2) -- Dorian "Give someone a fish and they eat for a day; t...

Editing an External Web Query Import
Hi, I've currently got an Excel sheet with a table I've imported from a web page I've created. This was done using the Data->Import External Data->New Web Query. The page itself is a CGI script and as such takes arguments in the address. I was wondering if anyone knows how I can alter that URL from a cell in Excel. Specifically I want to be able to change the hostname in a cell in Excel and the corresponding ?hostname='blah' to change. Any ideas would be greatly appreciated. Jim Data>get external data>run saved query. Right click the query and select edi...

insert an interactive excel file into word web page
I'm trying to insert a excel file into a word document with text, and then save it was as a web page, but I want to keep the excel part interactive. Any ideas? ...

Insert | File > Attachmnet-Button Drop Down ;What is the difference between Insert and Insert As Attachmnet
re: "Outlook2003, File-Insert-Options" On making new-email with Attachment-File(s), ** File Menu | Insert | File >>> (Brows and select File to insert ) then we can see the button "Insert", and write side Drop Down Arrow lower-right side of Dialog Box; If it clicked, we can see three options as follows: ** Insert Insert as text Insert as Attachment I can not recognize/understand the difference between "Insert" and "Insert as Attachment" *** What is the difference between Insert and Insert As Attachment ? I would appreciate y...

how to set up a query
I am using sql server 2005 express and have 3 tables Table1 Dept_Id (primary key) Dept_Name Table2 Employee_Id (primary key) Dept_Id (foreign key with table1) Employee_Name Table3 WorkSchedule_Id (primary key) Employee_Id (foreing key with table 2) Date_To_Work (date type) I want to list all the Departments (Dept_Name) that do not have anyone scheduled to work on a particular date (ie '1/20/2010' ) Any help would be appriciated. Thanks in advance, RABMissouri2010 Try this: SELECT dept_name FROM Table1 AS D WHERE NOT EXISTS(SELECT * ...

Inserting Hyperlinks in a Protected Sheet
Hi I run Excel 2000 and I have a protected worksheet that I share wit users in my organisation. I want to allow the insertion of a hyperlin to a specific file type within a specified directory on our server. 3 Questions: 1.Protection on disables the insert hyperlink command. Can this b overcome with worksheet activate code? 2.Can I limit the types of files (preferably by requiring the file t meet a mask format eg "z-*.xls")? 3.Can I limit the directory that can be linked, by referring to pathname stored in a cell on the active sheet? Would appreciate your suggestions. Thanks S...

Insert with a where condition
Hi, sql 2005 I have an insert statement that is ignoring the where condition. That is, I want to insert records when they do not already exist in the destination table. INSERT INTO dbo.tblmnuGroupPerm ( gId ,mtfID ,... ) SELECT @gID ,mtfID ,... FROM dbo.locmnuTabFunction AS ltf WHERE ltf.mtfID NOT IN ( SELECT gp.mtfID FROM dbo.tblmnuGroupPerm AS gp WHERE gp.gId=@gID AND gp.Deleted=0 ) Any ideas or recommendations appreciated :-) Many thanks, Jonathan It's OK... <oops "redFace">I did not correctly se...

Excel Query to Access Database Locks Users
We have one computer on our network of computer using Office 2007, the rest Office 2003. When the 2007 version is in a Excel query pulling from the network database it locks the database. Any way to solve that? ...

Can there be too many sub queries within a single query?
I am trying to combine the results from more than 15 queries into a single query in an attempt to save opening 15 different queries individually. The query runs successfully with the exception of the 15th, or last, query returning null cells. If I pull that sub query by itself it does return the correct data however. Has anyone experienced this in their projects? Thanks for your help, Rick I do not know as there is a limit to the number of subqueries but I read there is a limit to the total number of characters in the complete SQL statement. That would include subqueries,...

Issues with Integrating Multiple Spreadsheets for Reports or Queries?
We are keen to discuss and help with issues arising when needing to query, or produce reports using multiple Excel spreadsheets (Multiple Excel Spreadsheet Integration issues): Issues like: - We can=92t easily compare a choice of values in one spreadsheet with a choice in another worksheet - So we cannot easily answer the question =93what do all these rows have in common with those rows=94 Because: - We have to do a weekly report integrating multiple Project Plans, Financial Analyses =85 - We spend tons of time cutting and pasting, sorting and merging =96 the same process repeated every week...

Insert
I want to overtype in a Publisher text box. I find I can only insert. The "insert" key doesn't do anything. ...

Exporting Data From Query Into Excel
How can I have this process automatically done to have the data from a query after it's been ran to be exported into Excel in a specified location? -- Sincerely, Ronald R. Dodge, Jr. Master MOUS 2000 I have done some research on this method. While this method looks promising, there's one limitation. It states one MUST leave the "Range" argument as blank, when exporting data. The other thing I'm looking for, putting data from a query into a worksheet, which the name of the worksheet would be different from the name of the query. Based on the various things ...

how to insert data in a table
Hi Exprets; I am creating an access database in which I want to insert data in already created table. Kindly help. Regards, Vikky Vikky <love.excel@gmail.com> wrote in news:1194124711.012302.269990 @e34g2000pro.googlegroups.com: > Hi Exprets; > > I am creating an access database in which I want to insert data in > already created table. > > Kindly help. > > Regards, > > Vikky > Data from where? Do you want to import it from excel, from a text file, copy it from another table or type it in manually? -- Bob Quintal PA is y I've altere...

How do you insert page numbers larger than 1000?
I have my purchase orders set up as a Publisher document. When our organization upgraded from Publisher 2000 to Publisher 2002, the new version set parameters on the page numbers. This was one of those things that worked just fine in the previous version... Does anyone know how to turn it off or change it? Hi mregen (mregen@discussions.microsoft.com), in the newsgroups you posted: || I have my purchase orders set up as a Publisher document. When our || organization upgraded from Publisher 2000 to Publisher 2002, the new || version set parameters on the page numbers. This was one of those...

insert downloads into power point
i downloaded an application called "BioDigital Simulator" of an animated cleft lip/palate surgery and need it put into my power point presentation, but can't fiugre out how to do so.... very frustrating... What kind of file is this application? Is it a video? If so, what kind? MPEG? AVI? MOV? Or is it an EXE file? Something else? Which version of PPT are you using? -- Echo [MS PPT MVP] http://www.echosvoice.com What's new in PPT 2010? http://www.echosvoice.com/2010.htm Fixing PowerPoint Annoyances http://tinyurl.com/36grcd PowerPoint 2007 Complete Makeover...

Insert dataset to another database
I'm posting this to this group also since it pertains to queries, primarily. Hello, Using VB6/ADO, I'm thinking I can create a recordset and insert it into another table in a different Jet database, all within the execution of a single query. But, I can't seem to get it to work, even in an experiment in Access 2K. My sql in Access 2K: SELECT D.lorder as Ord, A.Lorder FROM [;Database = C:\MyDocuments\Acc2K\Wrk.mdb].OrdersData as A INNER JOIN [;Database = C:\Access\Work\Sales06.mdb].Detl1 as D On D.Lorder = a.lorder WHERE ((D.fg)= 'MXX-NC' Or (D.fg)= 'MXX.NC')...

Querying data tables
I routinely query data from another application into Excel. Is there any way to pass parameters into the query from the excel worksheet? That is, I want to put a start date and end date in the excel worksheet and then query for records dated within that range. I can edit the query easily enough, but I want to turn this over to users who would not understand how to use query and I don't want to spend a lot of time teaching repeatedly and mopping up their messes. ...

Insert a blank row
Hi, I need some help to insert a blank row in a range where column A has a series of dates. There will be several of the same dates and I need to both sort the dates and then insert the blank row at the end of each sequence. In the blank row I need to total figures that will be in columns B through to G. Thanks, Jim S Hi Jim maybe an easier solution 1. Sort your data (use 'Data - Sort', e.g., column A ascending) 2. Use 'Data - Subtotals' This will insert a row after each date and calculate subtotals automatically for you HTH Frank anon wrote: > Hi, > I need some...

How do I insert a letter into an existing word document?
I am working on a large document that I need to add several letters that are on our letterhead. If I cut and paste the letter, the letterhead header becomes skewed. This is just one issue I'm having with the document! Also need to know how to merge 3 separate documents together once I insert the letters that I need! Help! What do you mean by "skewed"? To preserve the data from the header of the document, you will need to insert it into a Section of its own separated from the rest of the document by Next page Section breaks before and after it with the headers...