473,320 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

parsing XML in C#

MR
i apologize in advance for what i know is a simple question and for
reposting (albeit with more specifics as to what I need) , but i am being
exposed to the first time to xml and have not been able to begin to resolve
this problem.

(i am able to do string manipulations, i.e. indexof and substrings, but
obviously there has to be a better way)

considering the following XML string that i receive:

<BusinessEntity xsi:type="DynamicEntity" Name="contact"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.microsoft.com/crm/2006/WebServices">
<Properties>
<Property xsi:type="KeyProperty" Name="contactid">
<Value>{80FB716B-B189-DA11-84BD-0003FFC6732A}</Value>
</Property>
<Property xsi:type="StringProperty" Name="duplicateid">
<Value>8e0c0022-2078-4017-9630-6453e80695c0</Value>
</Property>
</Properties>
</BusinessEntity
I need to obtain the values of the two fields contactid and duplicateid. I
am using C# and VS.NET 2003.
How do I do this?

thanks
m

Jan 25 '06 #1
1 1653
One way would be to load the string into an XML document and use XPath
queries:

XmlDocument doc = new XmlDocument();
doc.Load(<your xml string);

//Since you use an namespace, this is required for the xpath queries
XmlNamespaceManager nsmgr = new XmlNamspaceManager(doc.NameTable);
nsmgr.Namespaces.Add("N",
"http://schemas.microsoft.com/crm/2006/WebServices");

XmlNode contactIdNode =
doc.SelectSingleNode("/N:BusinessEntity/N:Properties/N:Property[@Name="contactid"]/N:Value",
nsmgr);
XmlNode duplicateIdNode =
doc.SelectSingleNode("/N:BusinessEntity/N:Properties/N:Property[@Name="duplicateid"]/N:Value",
nsmgr);

Guid contactID = new Guid(contactIdNode.InnerText);
Guid duplicateID = new Guid(duplicateIdNode.InnerText);

Hope this helps (or at least points you in the right direction).

Matt Dinovo
"MR" <co******@newsgroup.nospam> wrote in message
news:O4**************@TK2MSFTNGP14.phx.gbl...
i apologize in advance for what i know is a simple question and for
reposting (albeit with more specifics as to what I need) , but i am being
exposed to the first time to xml and have not been able to begin to
resolve
this problem.

(i am able to do string manipulations, i.e. indexof and substrings, but
obviously there has to be a better way)

considering the following XML string that i receive:

<BusinessEntity xsi:type="DynamicEntity" Name="contact"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.microsoft.com/crm/2006/WebServices">
<Properties>
<Property xsi:type="KeyProperty" Name="contactid">
<Value>{80FB716B-B189-DA11-84BD-0003FFC6732A}</Value>
</Property>
<Property xsi:type="StringProperty" Name="duplicateid">
<Value>8e0c0022-2078-4017-9630-6453e80695c0</Value>
</Property>
</Properties>
</BusinessEntity
I need to obtain the values of the two fields contactid and duplicateid. I
am using C# and VS.NET 2003.
How do I do this?

thanks
m

Jan 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
0
by: Pentti | last post by:
Can anyone help to understand why re-parsing occurs on a remote database (using database links), even though we are using a prepared statement on the local database: Scenario: ======== We...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
5
by: randy | last post by:
Can some point me to a good example of parsing XML using C# 2.0? Thanks
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
7
by: Daniel Fetchinson | last post by:
Many times a more user friendly date format is convenient than the pure date and time. For example for a date that is yesterday I would like to see "yesterday" instead of the date itself. And for...
1
by: eyeore | last post by:
Hello everyone my String reverse code works but my professor wants me to use pop top push or Stack code and parsing code could you please teach me how to make this code work with pop top push or...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.