newbie question on finding and editing

Using vb.net, I need to search through XML files to locate specific elements 
and once found,  update attributes of their companion elements. In plain 
language, I need to find specific book titles and update note information 
about each book. Not every book would be updated; just selected ones.

So, I am confused whether to use DOM, XPath, both, or something else? My 
understandig of Xpathnavigator is that it is a read-only class. And DOM seems 
good for mass updates, but how to use it to find things? Thanks for any 
advise!

george
0
1/30/2005 5:39:03 PM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
356 Views

Similar Articles

[PageSpeed] 38

Hi Geoge,

I'd suggest you use Xml DOM and XmlElement. Take a look at these 
documentations:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemxmlxmldocumentmemberstopic.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemxmlxmlelementmemberstopic.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemxmlxmlelementclasssetattributetopic.asp

You can do something like this(This is C# sintax, VB syntax is similar):

XmlDocument  xmlDoc = new XmlDocument();
XmlTextReader reader = new XmlTextReader("C:\temp\booklist.xml");
reader.XmlResolver = null;
xmlDoc.Load(reader);

//get all the book nodes using XPath
XmlNodeList  bookNodes = xmlDoc.SelectNodes("//book");

//Iterate each book nodes 
foreach (XmlElement  book in bookNodes)
{
   //your test statements
   //you can update the //book attributes and element
   book.SetAttributes("ISBN", <new value here>);
   //get child Element
   XmlElement  info =  book.SelectSingleNode("./info");
}

Assume from the following XML file:

<BookList>
   <book ISBN="">
      <title/>
      <authors><author/></authors>
      <info/>
      ................
   <book>
</BookList>

Hope this helps!
--Yingzi Le
LongHorn SDK Team

This posting is provided "AS IS" with no warranties, and confers no rights. 

--------------------
>Thread-Topic: newbie question on finding and editing
>thread-index: AcUG8pb67494fsO0SOW2EUmyW6puzQ==
>X-WBNR-Posting-Host: 63.231.157.145
>From: =?Utf-8?B?R2VvcmdlQXRraW5z?= <GeorgeAtkins@discussions.microsoft.com>
>Subject: newbie question on finding and editing
>Date: Sun, 30 Jan 2005 09:39:03 -0800
>Lines: 11
>Message-ID: <586DEDB9-157F-4CFB-9921-B00D1EA23AF9@microsoft.com>
>MIME-Version: 1.0
>Content-Type: text/plain;
>	charset="Utf-8"
>Content-Transfer-Encoding: 7bit
>X-Newsreader: Microsoft CDO for Windows 2000
>Content-Class: urn:content-classes:message
>Importance: normal
>Priority: normal
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
>Newsgroups: microsoft.public.dotnet.xml
>NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
>Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
>Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.xml:25160
>X-Tomcat-NG: microsoft.public.dotnet.xml
>
>Using vb.net, I need to search through XML files to locate specific 
elements 
>and once found,  update attributes of their companion elements. In plain 
>language, I need to find specific book titles and update note information 
>about each book. Not every book would be updated; just selected ones.
>
>So, I am confused whether to use DOM, XPath, both, or something else? My 
>understandig of Xpathnavigator is that it is a read-only class. And DOM 
seems 
>good for mass updates, but how to use it to find things? Thanks for any 
>advise!
>
>george
>



0
yingzile (9)
1/31/2005 8:40:13 PM
Thanks for the refs and examples! I actually have waded through these before; 
I was confused by apparent differences between capabilities of DOM and XPATH 
and other searching methods. Which is to say, I was over my head. I also 
appreciate the sample code, which is easy to understand, by the way. 

My need is not so straightforward as iterating and changing every occurrence 
of an element. Rather, I have to search for specific book titles within the 
collection and update a related quiz field for that book. In XML terms, I 
think, I need to find specific attribute text for a given element, then find 
a sibling element and update its attribute text.

So, I'll re-read those listings, but I may go out and find a good book that 
offers more contextual help and examples, as well. 

Thanks again.

George

"Yingzi Le" wrote:

> Hi Geoge,
> 
> I'd suggest you use Xml DOM and XmlElement. Take a look at these 
> documentations:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
> frlrfsystemxmlxmldocumentmemberstopic.asp
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
> frlrfsystemxmlxmlelementmemberstopic.asp
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
> frlrfsystemxmlxmlelementclasssetattributetopic.asp
> 
> You can do something like this(This is C# sintax, VB syntax is similar):
> 
> XmlDocument  xmlDoc = new XmlDocument();
> XmlTextReader reader = new XmlTextReader("C:\temp\booklist.xml");
> reader.XmlResolver = null;
> xmlDoc.Load(reader);
> 
> //get all the book nodes using XPath
> XmlNodeList  bookNodes = xmlDoc.SelectNodes("//book");
> 
> //Iterate each book nodes 
> foreach (XmlElement  book in bookNodes)
> {
>    //your test statements
>    //you can update the //book attributes and element
>    book.SetAttributes("ISBN", <new value here>);
>    //get child Element
>    XmlElement  info =  book.SelectSingleNode("./info");
> }
> 
> Assume from the following XML file:
> 
> <BookList>
>    <book ISBN="">
>       <title/>
>       <authors><author/></authors>
>       <info/>
>       ................
>    <book>
> </BookList>
> 
> Hope this helps!
> --Yingzi Le
> LongHorn SDK Team
> 
> This posting is provided "AS IS" with no warranties, and confers no rights. 
> 
> --------------------
> >Thread-Topic: newbie question on finding and editing
> >thread-index: AcUG8pb67494fsO0SOW2EUmyW6puzQ==
> >X-WBNR-Posting-Host: 63.231.157.145
> >From: =?Utf-8?B?R2VvcmdlQXRraW5z?= <GeorgeAtkins@discussions.microsoft.com>
> >Subject: newbie question on finding and editing
> >Date: Sun, 30 Jan 2005 09:39:03 -0800
> >Lines: 11
> >Message-ID: <586DEDB9-157F-4CFB-9921-B00D1EA23AF9@microsoft.com>
> >MIME-Version: 1.0
> >Content-Type: text/plain;
> >	charset="Utf-8"
> >Content-Transfer-Encoding: 7bit
> >X-Newsreader: Microsoft CDO for Windows 2000
> >Content-Class: urn:content-classes:message
> >Importance: normal
> >Priority: normal
> >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
> >Newsgroups: microsoft.public.dotnet.xml
> >NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
> >Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
> >Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.xml:25160
> >X-Tomcat-NG: microsoft.public.dotnet.xml
> >
> >Using vb.net, I need to search through XML files to locate specific 
> elements 
> >and once found,  update attributes of their companion elements. In plain 
> >language, I need to find specific book titles and update note information 
> >about each book. Not every book would be updated; just selected ones.
> >
> >So, I am confused whether to use DOM, XPath, both, or something else? My 
> >understandig of Xpathnavigator is that it is a read-only class. And DOM 
> seems 
> >good for mass updates, but how to use it to find things? Thanks for any 
> >advise!
> >
> >george
> >
> 
> 
> 
> 
0
1/31/2005 10:05:01 PM
Reply:

Similar Artilces:

Find and Replace #7
Hi, need help with finding and replacing data. I found this macro on another site Sub myReplace() Columns("A:C").Replace What:=Range("E1").Value Replacement:=Range("E2").Value, LookAt:=xlWhole, SearchOrder:=xlByRows MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False End Sub Was wondering if anyone could adapt it for my needs. Tried to modify i myself but don't know anything about VBA. The data that I want to replace is in a range called "data" (A2:H500 on sheet "datainput" Replace what ("C5") on "search" sh...

can I find merged cells?
I'm trying to sort and get the message "merged cells must be the same size". How can I 'find' the merged cells? David, here is a macro by Dave Peterson that will do it Sub Found_Merged_Cells() 'macro looks for merged cells 'By Dave Peterson Dim myCell As Range Dim resp As Long For Each myCell In ActiveSheet.UsedRange.Cells If myCell.MergeCells Then If myCell.Address = myCell.MergeArea(1).Address Then resp = MsgBox(prompt:="found: " _ & myCell.MergeArea.Addre...

Opening/editing/saving excel file
I am using Access/Excel 2003 and I'm trying to open a file called Quad_Charts_Template.xls from my C drive, dump some data on one of the sheets, make a couple changes and save it with a specific name. This is the code I have to choose my record sorce: Set rst = CurrentDb.OpenRecordset("qry_Avg_Age_Trend_Source_Data") The worksheet is called "AAT_Raw_Data", which will always be the 1st sheet and I want to copy the data from rst onto the sheet starting at A1. I also want to bold the header row and set the auto filter as active. And finally I want to sav...

Custom workflow activity question
Hi all, It seems to be impossible to use any custom entities / attributes in the custom workflow activities. Any suggestion how to accomplish this a simple way? Thanks in advance, Robert I have seen post somewhere about accessing custom entities , you need to google it. As well as custom attributes are concerned , you need to use dynamic entity for example accessing "new_link" which is custom attribute : DynamicEntity regardingAccount = (DynamicEntity)retrieved.BusinessEntity; if (regardingAccount.Properties.Contains("new_link")) { // do somethi...

Subquery to find consecutive dates
Howdy Folks, I have a table that contains a series of asbestos sampling dates at several different locations. A simplified version of the structure is as shown below: [Location] [Sampler] - Company that performed the sampling [Sample Date] [Result] - Numerical Result [Detection Flag] - Yes or No When the detection flag is "Y" for a given day, I want to know if the next day also has a detection. If not, I want to ignore that detection. If yes, I want the first day to get flagged with a "1" and the subsequent day to be flagged with a "2". This gets trickier when ...

Finding a Central Location
I have a Table that has over 107,000 records in it. It includes origin city and state and destination city and state. I am trying to figure out where the best place to put a new warehouse or warehouses would be using all of this shipping data. Is there any way that I can do that using Access 2000? If I could put all of the locations on a map of some kind that might be useful as well. Thanks for any help you can give me and Happy Holidays! ...

T-SQL query for finding shared user and team records
Hi all, I'm new to CRM and would appreciate any help. I need to find account records that record owners have shared to users or teams in CRM. I've found out that this requires direct query to filtered view tables. Microsoft responded as below by I need actual T-SQL query. Can anyone help with this? You would need to write a query against the PrincipalObjectAccess table and you would need to have joins to the other related tables. If you tried to have it all displayed using one query, it would be a pretty complex query. This is because you would need to join to the FilteredA...

output question
#define the properties to be returned ($colPropList is an array) $colProplist = "name","member" foreach ($i in $colPropList) { $Searcher.PropertiesToLoad.Add($i) } Above is the code to set the properties for a directory search but it produces a 0 1 in the outputs. Any one happen to have experienced this and how to get rid of the 0 1 output ? Thanks Redirect result of the method to $null { $Searcher.PropertiesToLoad.Add($i) > $null } -Paul "Chris" wrote: > #define the properties to be returned ($colPropList is an array) > $col...

Report writer function/calculated field question
I have a string field that consists of a number followed by a decimal followed by 5 zeroes. The number is always a whole number so I want to remove the decimal and the 5 zeroes. However, since the field is a string, I'm struggling to find a way to do that. Does anybody have any suggestions? Thanks. Zack I would use the RW_Strip user defined function. This function will return the value of the string with all occurrences of the specified characters stripped out. So you want to strip out .00000 and retrieve the remaining value? You would pass in the string field and then the characters y...

Editing Contact Information
Does anyone know if there's an easier way to edit contact information? I can't seem to cut and paste text if I need to update or edit someone's email address or other contact information. This a basic function but it doesn't seem to work on Live .. Is this a defect in the system or am I'm missing something? Thank you There are two steps before you can edit: click Edit Contact click one of the categories under Summary You will probably want to click Contact. -- Ron Sommer MS MVP- Windows Live Mail "Editing Contact Information" wrote in ...

ExBPA config question
Can I modify the XML config file to set custom rules that fit my needs? ...

Traversing XML with Linq to XML
Hi I am struggling to navigate an XElement and I'm not sure what is going wrong. Here's my XML via vb's xml literals Dim l_testSchema = _ <Mappings> <Definitions> <ItemGroup> <Parent>Table</Parent> <Name>Name</Name> </ItemGroup> <Item> <Parent>Column</Parent> <Name>Name</Name> &l...

Table and query question
I would like to create a table that will relate an account to its parent(s). 1 account can have multiple parents, and 1 parent can have multiple accounts. And, a parent can have a master parent. For ex: Account 1 can have Parent 1. Account 2 can have Parent 1 and Parent 2. Parent 1 can have Parent 2. And, the queries that I will perform will request these data: 1. give me all parents of Account 1. The query should return Parent 1 and Parent 2 (because Parent 2 is the parent of Parent 1) 2. give me all parents of Account 2. The query should return Parent 1 and Parent 2 3. give...

Quick Question on Categories
An anally organized person just realized this question... ;-) Maybe someone can help me out with your solution to the problem? I'd think that going to /see/ movies is considered different from buying them on video. So, when I go see a movie, is it considered Movies & Video, or on Cultural Events? Seeing a movie is questionable as a cultural event... Thanks, Kenneth "Kenneth Pardue" <kennethNOSPAM@pardue.com> wrote in message news:vnprkfirgng4de@corp.supernews.com... > An anally organized person just realized this question... ;-) > > Maybe someone can he...

absolutely classic DLL question
Hello to all. Please, let some professional from people here guide me for creating a DLL library. I have some classes, some files, some functions, etc. DLL will be built without any guidance. Still... I need help. I need after this to create one .LIB which actually does not "enter" statically in target out file, but just loads this .DLL. In this manner is Windows Sockets 2 - using ws2_32.lib, actually linked out file to load/use ws2_32.dll. Funny, but I dont know how this must be done. Please, I need short, concrete and precise guidance. Will be very grateful for your help. Than...

Basic INDEX(MATCH()) Question:
I am currently using an INDEX() function to do a basic data retrieval by specifying both the collumn and rows. INDEX(p1rn1,1,18) p1rn1 is C2:AE28 the 1,18 retrieves what is in cell T3 in cell Q:S3 (Cells Q3 -> S3 are merged) is the text string "Weap Dam Rec" Is it possible to use INDEX(p1rn1,MATCH("Weap Dam Rec",?,?),?) to find the data in T3, if so, what is the wording of the function? If INDEX() can't do it, is there anyhting that can? for the billionth time Thanks Adam Hi! > INDEX(p1rn1,1,18) > > p1rn1 is C2:AE28 > > the 1,18 retrieves ...

newbie question re: learning curve
I am a complete newbie to Publisher. I am slightly familiar with Corel Draw and InDesign, but my new job only offers Publisher as a software. I am a quick learner, but I'd like to know a couple things: Can I import InDesign files? How similar to the other Microsft products is the interface? Can I make complex designs with Publisher (most will be simple). Thank you. Libbi -- Triple Double ------------------------------------------------------------------------ Triple Double's Profile: http://nettechguide.com/forums/member.php?u=599 View this thread: http://nettechguide.com/fo...

Backup & Restore-editing a GL segment
Hi Folks I have a template company in which I have everything defined with their respective GL control accounts - ie: Customer, Inventory & Vendor classes; Ret Inc; Tax details and Schedules, Bank Management, Fixed Assets and a full GL. I need to back it up and restore it multiple times into about 20 other companies and then the only thing I want to change in the new company is Seg 1 of the GL code in every table where the segments are held. I do not need to change the account indexes-they will remain the same. I can easily run a SQL script to update the GL00100 segment 1 field...

ISA 2004 Question
I have had ISA 2004 installed on my SBS 2003 server every since it was put into service and it has never allowed LAN workstations to access the Internet without having proxy settings in the web browser. I had to do a restore recently and after that was completed I noticed that if I unchecked the use proxy check mark in my browser I could still access Internet pages and of course my restricted web page settings were being ignored because of not using the server proxy. The proxy is working because when I have the proxy in the browser check to use it does block the web pages in my &...

Taskbar Outlook Question
I have an Outlook icon next to the clock right hand lower corner. How do I delete it? I already have one in my taskbar. Thanks, david You can't but you can customize you're Notification Area to hide it or rightclick it and choose "Hide when minimized" to remove it from the Taskbar. -- Robert Sparnaaij [MVP-Outlook] www.howto-outlook.com Tips of the month: -Properly back-up and restore your Outlook data -Create an Office 2003 CD slipstreamed with Service Pack 1 ----- "david" <chevie@mail.com> wrote in message news:jdeRd.50484$Th1.39608@bgtnsc04-ne...

POP3 Internet Mail Question
I am running 1 windows 2003 server with Exchange 2003 on it. This server hosts our internal & external email for our domain name xxx.com However we have another domain name (xxy.com) that we use for internet mail that is hosted by another provider. We would like to bring this in-house and host it on our exchange server. Is there a way to configure the exchange server to host internet mail (Pop3 accounts) with a different domain name? What is the best way to set this up? thanks =?Utf-8?B?Z2tyYXNub2Zm?= <gkras19@aol.com> wrote in news:7C1FB197-B7A9-4A9E-A2D1-933577EFF0B0@micr...

Find Value; Return Row number
Goodmorning everybody! I was wondering if someone could help me with the following problem: "I wanted to make a macro which would find the first value (counting from a1) that matches the value stated in C14 of "FORM". When it gives a match I want to return the row number to "Sheet2". I tested it with dates of which I was certain it had to find a match (as I entered them myself in "Sheet1") Still it returns: "Named Argument not Found" (Runtime error 448)" I hope someon sees my mistake(s). Thanks in Advance!! Sub TestDelete() l = Sheet...

change cell values from an edit box
Is there any way to change a cell's value with an edit box? I've used drop down lists to change/update values, but I have no experience at all with edit boxes. Any help would be greatly appreciated. Mike ...

Validity checking
Office 2003. Spreadsheet contains aged test data (specimen created date, test date, test result, design target ...) I'd like to use conditional formatting to highlight test results that fall below a threshold curve, but I don't know how to obtain intermediate values from the curve. Known: Age % of at design test target 7 days 70% 14 days 90% 28 days 100% Does Excel include a function that will give me the percentage of design target for any arbitrary test age? (well, less t...

Mailbox Manager questions
Hello, We are running Exchange 2003, sp1. Is there a tutorial somewhere that shows how to specificy groups/users for the mailbox management selection. When I get into the window to select users, it doesn't select them the way I'm asking. i.e. I try and select a security group and it selects a few users. I also can't seem to select multiple users correctly. Lastly, we would like to archive old Calendar items. The problem seems to be that if we archive recurring meetings that they will get deleted on future items. Thanks, Sun ...