How parse XML values from a string?

I have a string (see below) that I want to parse out the values.  As you can 
see, some are element-based and some are attribute-based.

<METADATA version="Format5"><TITLE value="Adrenaline 
Rush"/><DESCRIPTION>Take a thrilling look at the world of skydiving and base 
jumping - parachuting from a building, a bridge or a cliff. With 
breathtaking views of skydiving over the Florida Keys, the Mojave Desert and 
the magnificent Fjords of Norway, this giant-screen experience explores the 
psychological and physiological forces behind risk-tasking and the physics 
involved in high-risk activities.</DESCRIPTION><BARCODE 
value="014381203820"/><BARCODE value="400002716808"/><PREVIEWIMAGE 
value="IME120382C.png"/><MEDIATYPE value="DVD"/></METADATA>

Can someone please show me what the code would look like to do this?

Thanks,
Ron

P.S. Note that no nodes will be repeated (so I'm guessing it should be 
simpler). -thx


0
rcook (5)
2/12/2007 12:19:59 AM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
592 Views

Similar Articles

[PageSpeed] 54

Ronald S. Cook wrote:
> I have a string (see below) that I want to parse out the values.  As you can 
> see, some are element-based and some are attribute-based.
> 
> <METADATA version="Format5"><TITLE value="Adrenaline 
> Rush"/><DESCRIPTION>Take a thrilling look at the world of skydiving and base 
> jumping - parachuting from a building, a bridge or a cliff. With 
> breathtaking views of skydiving over the Florida Keys, the Mojave Desert and 
> the magnificent Fjords of Norway, this giant-screen experience explores the 
> psychological and physiological forces behind risk-tasking and the physics 
> involved in high-risk activities.</DESCRIPTION><BARCODE 
> value="014381203820"/><BARCODE value="400002716808"/><PREVIEWIMAGE 
> value="IME120382C.png"/><MEDIATYPE value="DVD"/></METADATA>
> 
> Can someone please show me what the code would look like to do this?

Here is C# .NET 2.0 code that uses XmlReader to pull in nodes, if an 
element has attributes if outputs the attributes, if there are no 
attributes it reads out the element contents:

             using (XmlReader xmlReader = XmlReader.Create(@"file.xml"))
             {
                 while (xmlReader.Read())
                 {
                     if (xmlReader.NodeType == XmlNodeType.Element)
                     {
                         Console.WriteLine("Reading element {0}:", 
xmlReader.Name);
                         if (xmlReader.HasAttributes)
                         {
                             while (xmlReader.MoveToNextAttribute())
                             {
                                 Console.WriteLine("Attribute {0}={1}.", 
xmlReader.Name, xmlReader.Value);
                             }
                         }
                         else
                         {
                             Console.WriteLine(
"Element content: \"{0}\".", xmlReader.ReadElementContentAsString());
                         }
                         Console.WriteLine();
                     }
                 }
             }

..NET has various other ways (DOM, XPath, XSLT) to parse and extract XML 
data so depending on your needs other ways might be more comfortable 
than using XmlReader.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
2/12/2007 1:43:25 PM
Reply:

Similar Artilces:

Ordering xml using xsl in c#
Hi, I have a xml dataset I'd like to order, and save in that order. I've written an xsl to do the transformation, but because the xml file has a xsd namespace, it doesn't work. A cutdown version of the xml file looks like this: <?xml version="1.0" standalone="yes"?> <hsPrinters xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" xmlns="http://tempuri.org/printer.xsd"> <city> <code>LN</code> <name>London</name> <comment>Herbert Smith London Offices</comment> </ci...

returning a text value
I think this is simple but I am confused with it. I am creating a softball roster. Column a is the positions, Column b is player for inning 1. C is inning 2 and so on. So with my current grid I can see who is in which position by inning. My second grid will show players name followed by position being played. Column F lists all the players. I need a function that will search column b for matches to column F and insert the position (column a) in column G. Check Help for Vlookup. Regards, Fred "Tim" <Tim@discussions.microsoft.com> wrote in message news:133...

Formula Help
Hello, I have searched the web but can't seem to find the solution for this problem. I have a string of data in a column of cells that look like this: COMPANY NAME Contact Person Address COMPANY NAME Contact Person Address I need to pull the company name (which are in all caps) from the first part of this string for each cell. How do I get Excel to pull the company name (anywhere from 1 words to 6 or 7 words) and leave the rest? Thanks in advance for your help! HI, Try this. ALT+F11 tp open Vb editor. Right click 'This workbook' and insert module and pas...

Parsing Question
I've done parsing where you have one delimiter such as a comma or space. What if you have more than one? Example data: sStr(0) = "3/9" sStr(1) = "3/11 3/15-" sStr(2) = "3/8+ 3/12" sStr(3) = "3/9 3/15" sStr(4) = "3/8- 3/10+ 3/15" The strings above are Month/Day with some having an additional - or + character next to it. These dates are extracted from Excel cells as strings. I need to break those strings down into individual dates. So for sStr(4), I need to parse out "3/8", "3/10" and "3/15&...

#VALUE!
Is there a way to hide the "#value!" so it does not show in the cell? One way is to put a conditional format and look for =ISERROR(A1) where A1 is the cell of interest. You can change the font to white. Alternatively, you could put =if(iserror(Your formula),"",Your formula) -- HTH, Barb Reinhardt "dwolf" wrote: > Is there a way to hide the "#value!" so it does not show in the cell? Hi Try something like this: =If(IsError(yourFormula),"",yourFormula) Hopes this helps. .... Per On 11 Jan., 21:0...

Labeling The Right Hand Side Of A Graph With Axis Values ?
Hello, Have a very simple graph of dates along the X and Blood p along the left vertical. Typical simple graph. Is there any way I can have the Y axis value labels also appear on the right hand vertical edge of the graph (in addition to the left side) ? Can't believe there isn't a way to do it, but just don't see any option for it. Thanks, B. Hi, You need to have 2 series in order to use both sets of Y axis. Explanation for a column chart is given here. http://www.andypope.info/tips/tip005.htm The same applys to line chart although obviously you do not have to worry a...

how to parse <?xml version="1.0" encoding="UTF-8"?> with xpath? is it possible?
how to parse <?xml version="1.0" encoding="UTF-8"?> with xpath? is it possible? "Daniel" <softwareengineer98037@yahoo.com> wrote in message news:%23g11DbDOGHA.2176@TK2MSFTNGP10.phx.gbl... > how to parse <?xml version="1.0" encoding="UTF-8"?> with xpath? is it > possible? No -- the xml declaration is not represented in the XML Infoset. Cheers, Dimitre Novatchev ...

Highlighting matching values in a two column spreadsheet
I've got a spreadsheet with two columns of data. The first column is a list of words, for example: one three two eight seventwo nine three two The second column contains a list of all the words I want to check th first column for, e.g: two nine I want to be able to check the values of each cell in the second colum and highlight any cells in the first column that correspond with any o them. So in the example, 'two' 'seventwo' 'three two' and 'nine' woul all need to be highlighted. Any help would be greatly appreciated, thanks : -- trafficbroke -------...

Locating xmlns nodes in XML documents (for XML document metrics)
I've been writing an XML document analyzer that reads XML document and tracks the metrics of the document. Statistics such as a node count fo each type of XML node are printed out I am trying to locate 'xmlns' nodes using the XPath (not DOM or SAX) API Unfortunately the XPathNavigator concept of namespace nodes for eac element is only accessible via MoveToFirstNamespace() an MoveToNextNamespace(). The XPath model constructs a namespace node lis for EACH ELEMENT where each namespace node represents a namespace CURRENTL IN SCOPE for the current XML node I would like to easily loca...

Want make chart express Inventory value
want to make chart express inventory ending value ...

Counting rows, then counting values.
I have a lot of spreadsheets with many rows and columns of numbers. I need a way to find the highest value in each row, (mark it some how, bold the number maybe), then count the number of "highest" values are in each column. Is there an easy way to do this? Thank You, Michael Hi Michael You can use this to get the value =MAX(A1:A20) and this to count =COUNTIF(A1:A20,MAX(A1:A20)) -- Regards Ron de Bruin http://www.rondebruin.nl "Michael via OfficeKB.com" <forum@nospam.OfficeKB.com> wrote in message news:152907df2ac24b6ab6ee8d51d46958d9@OfficeKB.com... >...

How I can specify the length of a text or binary column to larger value?
When the using Microsoft Excel How I can specify the length of a text or binary column to a larger value? otherwise, if the length of a text or binary column not specified (or is specified as 0), the column length will be set to 255. Hi not really sure what you're trying to achieve? -- Regards Frank Kabel Frankfurt, Germany "Yue Wu" <wuyue15@hotmail.com> schrieb im Newsbeitrag news:433001c4a48d$76b0aa90$a601280a@phx.gbl... > When the using Microsoft Excel How I can specify the > length of a text or binary column to a larger value? > otherwise, if the lengt...

Parsing cells
Hi Folks, I have data in cells which is OCR`d from my phone bill, and some of the info is corrupt. Where I should be getting eg. 17 Nov 14:49 for date/time I am getting O17 Nov 14:49 or C17Nov 14:49. The reason is that there are unreadable icon characters to signify day or night. Questions: 1)How do I remove the faulty characters......they are always the first digit in the date if they are there. 2)How can I seperate the date and time into two adjasent colums of cells rather than their current format in one cell. Any and all help greatly appreciated. John Hi John You ca...

What is the quickest way to get an xml based dataset to add entries to SQL Server?
Because there is no 'datareader' involved, what is the most efficient way to get an XML based dataset to be added to an SQL server dataset? I would hate to have to create a new SQL connection and iterate through making "executenonquery" for each row in the dataset. That seems horribly in-efficient. I know of no other way to get an xml based dataset to push data to the database though. Any pointers? Thanks for any pointers, Peter Robbins Freelance Programmer C#/PHP "MurdockSE" <murdock@nc.rr.com> wrote in message news:1153922058.675709.165630@h48g2000cwc.go...

Inport/Eport XML
I am running Microsoft Office 2000 on my work computers. I am editing a database and I need said database to export a table named Data Table to a .xml file. I also need to be able to import a .xml file and have it added to the same table. I don't know if 2000 has the capability. Check your VBA references for an XML library. I am using 2003 and we have it. You use the xmlExport and xmlImport methods to do that. -- Dave Hargis, Microsoft Access MVP "Bobby.Dannels@gmail.com" wrote: > I am running Microsoft Office 2000 on my work computers. I am editing > a database a...

Adding to the cell value with a macro
I would like to select a cell with a product code (let's say cell B6 contains Part #ABC). I would like to activate that cell, click on a button to run a macro to change the quantity (lets say quantitiy is in cell A6.) If A6 is currently 0, a click would change it to 1. if it is 2, a click would change it to 3. On a sheet with many product numbers, the macro would start at the active cell, jumpone column to the left, and "1" and return to the cell to the right. I know this is possible, but can not seem to get there. Thanks in advance for your help Private Sub Comm...

Parse Nested Elements to Single DataGrid
I have been losing my mind trying to parse an XML document (with nested child elements, not all of which appear in each parent node) into a DataGrid object. What I want to do is "flatten" the XML document into a text document with a single row for each parent node (that has all of the values from all of the child nodes for that row) The DataView within VS 2005 IDE displays my 15 or so child tables - and knows that some parent rows don't have child rows in every relation - but trying to get all the child tables to go with the correct parent row programmatically is killin...

VLOOKUP to return subsequent values on same criteria
Hi. Wondering if this is possible in Excel alone, without using Access etc ; also, LOOKUP doesn't seem to be the function that will solve th problem for me. What I'm trying to do is the following: Sheet 1: (DATA) A B 1 PPE Vehicles 2 ABC XYZ 3 PPE Buildings 4 PPE Equipment 5 ABC RST 6 .... Sheet 2: (RESULTS) A 1 PPE 2 3 4 I want to lookup cell A1 on sheet 2, match it to rows 1,3,4 on sheet and return the values in column B on sheet 1 to cells A2 - A4 on shee 2. Essentially, I'd like a VLOOKUP function to return more than on value, or rather,...

generate xml ...
hi, i need to generate an xml files of some data in my database ... i've an xml sample of the result xml nad i've to create a xml with the same structure ... which it is the better and faster way? Can i retrieve a schema from the sample.xml and then write an xml based on this schema ? Might i use Dataset.readxmlschema , Dataset.readxml and Dataset.writexmlschema , Dataset.writexml ??? tnx in advance andrew ...

Advanced Filter for exact value
I tried to do advanced filter for the below list, where "BF BGA" is the header row: BF BGA BF304 C20 BF328 B15 BF348 B10 BF343 B11 BF294 C22 BF199 AD26 BF374 B4 BF1 E5 BF3 C2 BF4 E4 BF5 B1 Using the criteria: BGA C2 B1 The goal is to filter for the values C2 and B1 only. But it filters all values containing C2 and B1 as below: BF BGA BF304 C20 BF328 B15 BF348 B10 BF343 B11 BF294 C22 BF3 C2 BF5 B1 How can I filter on entire contents. Thanks, Madan Try this in your criteria range: BGA =C2 =B1 Debra Dalgleish has some tips (including this one) at: http://contextures.com/xla...

Concatenation operator within strings
How can the concatenation operator be included within strings? I have a function that concatenates the selected values from a listbox but would like to add " & "*" Or " to each value: Public Function ConcatList(frmWhichForm, varWhichControl) Dim varItem As Variant Dim stParameter As String Dim WhichForm As Form Dim WhichCntl As Control Set WhichForm = frmWhichForm Set WhichCntl = varWhichControl stParameter = "" For Each varItem In WhichCntl.ItemsSelected stParameter = stParameter & WhichCntl.ItemData(varItem) & " ______________ "...

Setting the cell's value with the Vlookup value...
Can someone help me with this? Is there a way to set the cells values to the value the Vlooku returns? Reason being is that whenever the sheet is opened it takes a lot o time recalulating. Thank you in advance ----------------------------------------------- ~~ Message posted from http://www.ExcelTip.com ~~View and post usenet messages directly from http://www.ExcelForum.com >-----Original Message----- > >Can someone help me with this? > >Is there a way to set the cells values to the value the Vlookup >returns? > >Reason being is that whenever the sheet is opene...

divide values by 10000
Hi! I have several hundreds of cells that contain big numbers. Now I want to divide all of them, in one step!, by 10000... Couldn't find a way to do this.. Any idea? Thanks. -- danielpaval ------------------------------------------------------------------------ danielpaval's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=27876 View this thread: http://www.excelforum.com/showthread.php?threadid=473798 In a blank cell somewhere on your sheet, enter 10000. Copy this cell (CTRL+C). Highlight the range you want to divide by 10000. Select Edit>Paste Spec...

xml graphic representation
I'm new to using XML, so I'm seeking some general pointers about approaching a project. I'd like to read the sitemap xml file, and generate a graphic representation of the website from the site map. I would like to do this dynamically (creating the page from the current sitemap file). I'm wondering if there are some built in functions I can use, for example to: 1) parse the xml file, creating units at each node 2) interpret levels within the file 3) create graphics based on each node, writing the node property in the text of the graphic object. I know what functions I'...

Reverse values but not X axis
I am trying to create a chart showing staff performance reviews where 1 is the highest value and 5 is the lowest (based on our rating system). Obviously excel creates the axis with values from 0 to 5. If I reverse values it basically flips the chart upside down with the X axis above. Is there a way to reverse values only? Many thanks in advance. Nadia Hi, As well as ticking "Values in Reverse Order" also tick "Category (x) axis crosses at Maximum value" Cheers Andy Nadia wrote: > I am trying to create a chart showing staff performance reviews where 1 is > t...