473,786 Members | 2,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert String Value into XML

Hi All,

I am pretty to new to .NET/C# so go easy!

I am developing a Web Service call to a Java Web Service and it is all
working fine - it is returning me back a String value which in all
reality is an XML file (the content of the string is a valid well-formed
XML packet). How can I get this string into an XML object so I can use
the XML functions / operations in .NET? An example of my XML String is
below:
<?xml version="1.0" encoding="UTF-8"?>
<NOVA version="1.0">
<PROCESSGUID>B1 367940-802E-9665-4305EF47E9AC81F 1</PROCESSGUID>
<REQUEST><USERN AME>foo</USERNAME><PASSW ORD>foo</PASSWORD>
<COMPONENT>Test </COMPONENT>
<ARGUMENTS><add ress>earth</address><foo>ea rth</foo></ARGUMENTS>
<METHOD>foo</METHOD></REQUEST><RESPON SE><SUCCESS>tru e</SUCCESS><RESULT >I
worked!</RESULT><RESPONS EDATETIME>2006-07-27
18:19:35</RESPONSEDATETIM E><ERROR>
<TYPE/><CODE/><MESSAGE/><DETAIL/></ERROR></RESPONSE></NOVA>
How could I get say, the "SUCCESS" value from this string

Hope some of you gurus can help ;-p

Thanks
Jul 27 '06 #1
4 30576
All you have to do is pass the string to the LoadXml method of the
XmlDocument class. Then, you can use XPath to get the values of the
elements/attributes in the document.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Java Apache" <te************ @ukonline.co.uk wrote in message
news:Cw******** *****@fe1.news. blueyonder.co.u k...
Hi All,

I am pretty to new to .NET/C# so go easy!

I am developing a Web Service call to a Java Web Service and it is all
working fine - it is returning me back a String value which in all reality
is an XML file (the content of the string is a valid well-formed XML
packet). How can I get this string into an XML object so I can use the
XML functions / operations in .NET? An example of my XML String is below:
<?xml version="1.0" encoding="UTF-8"?>
<NOVA version="1.0">
<PROCESSGUID>B1 367940-802E-9665-4305EF47E9AC81F 1</PROCESSGUID>
<REQUEST><USERN AME>foo</USERNAME><PASSW ORD>foo</PASSWORD>
<COMPONENT>Test </COMPONENT>
<ARGUMENTS><add ress>earth</address><foo>ea rth</foo></ARGUMENTS>
<METHOD>foo</METHOD></REQUEST><RESPON SE><SUCCESS>tru e</SUCCESS><RESULT >I
worked!</RESULT><RESPONS EDATETIME>2006-07-27
18:19:35</RESPONSEDATETIM E><ERROR>
<TYPE/><CODE/><MESSAGE/><DETAIL/></ERROR></RESPONSE></NOVA>
How could I get say, the "SUCCESS" value from this string

Hope some of you gurus can help ;-p

Thanks

Jul 27 '06 #2

Here are some key words to get you going:

Namely, they are
XmlElement , XmlNodeList , XmlNode
methods:
SelectNodes
SelectSingleNod e

If you go to
http://sholliday.spaces.msn.com/ 2/8/2006 entry
and download hte sample, you 'll find some xml code.

Below are some snipplets, they are *not* meant to work, just show some
syntax.


XmlElement root;

if (null!=root.Att ributes["abc" ])
{
masterPortNumbe r = root.Attributes["abc"].Value ;

}

XmlNodeList myNL = root.SelectNode s("//someXpath/someChild1/someChild2);
if (myNL.Count <= 0)
{
throw new ArgumentExcepti on("No matches found ");
}

foreach (XmlNode xn in myNL )
{

}

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote in
message news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
All you have to do is pass the string to the LoadXml method of the
XmlDocument class. Then, you can use XPath to get the values of the
elements/attributes in the document.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Java Apache" <te************ @ukonline.co.uk wrote in message
news:Cw******** *****@fe1.news. blueyonder.co.u k...
Hi All,

I am pretty to new to .NET/C# so go easy!

I am developing a Web Service call to a Java Web Service and it is all
working fine - it is returning me back a String value which in all
reality
is an XML file (the content of the string is a valid well-formed XML
packet). How can I get this string into an XML object so I can use the
XML functions / operations in .NET? An example of my XML String is
below:


<?xml version="1.0" encoding="UTF-8"?>
<NOVA version="1.0">
<PROCESSGUID>B1 367940-802E-9665-4305EF47E9AC81F 1</PROCESSGUID>
<REQUEST><USERN AME>foo</USERNAME><PASSW ORD>foo</PASSWORD>
<COMPONENT>Test </COMPONENT>
<ARGUMENTS><add ress>earth</address><foo>ea rth</foo></ARGUMENTS>
<METHOD>foo</METHOD></REQUEST><RESPON SE><SUCCESS>tru e</SUCCESS><RESULT >I
worked!</RESULT><RESPONS EDATETIME>2006-07-27
18:19:35</RESPONSEDATETIM E><ERROR>
<TYPE/><CODE/><MESSAGE/><DETAIL/></ERROR></RESPONSE></NOVA>
How could I get say, the "SUCCESS" value from this string

Hope some of you gurus can help ;-p

Thanks


Jul 27 '06 #3
It does and it doesn't, I am not sure how to use the XPath part!? I have
this so far..

string novaResponse = testInvoke.exte rnalRequest(sw. ToString());

NovaResponse is my XML string and it AOK.

I then have

xmlDoc.LoadXml( novaResponse); which is where I think you noted I
should be.....now for XPath? ;-p


Nicholas Paldino [.NET/C# MVP] wrote:
All you have to do is pass the string to the LoadXml method of the
XmlDocument class. Then, you can use XPath to get the values of the
elements/attributes in the document.

Hope this helps.

a
Jul 27 '06 #4
Look at the SelectSingleNod e method on the XmlDocument.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Java Apache" <te************ @ukonline.co.uk wrote in message
news:Wy******** ***********@fe2 .news.blueyonde r.co.uk...
It does and it doesn't, I am not sure how to use the XPath part!? I have
this so far..

string novaResponse = testInvoke.exte rnalRequest(sw. ToString());

NovaResponse is my XML string and it AOK.

I then have

xmlDoc.LoadXml( novaResponse); which is where I think you noted I should
be.....now for XPath? ;-p


Nicholas Paldino [.NET/C# MVP] wrote:
> All you have to do is pass the string to the LoadXml method of the
XmlDocument class. Then, you can use XPath to get the values of the
elements/attributes in the document.

Hope this helps.

a

Jul 27 '06 #5

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

Similar topics

2
3372
by: Erik Grob \(MCP\) | last post by:
Does anyone know where to find or how to write a quick user defined fucntion that will return a table object when passed the string name of the table object. The reason why I want dynamicallly set the table name in a stored procudue WITHOUT using concatination and exec a SQL String. Hence If @small_int_parameter_previous = 1 then @vchar_tablename = "sales_previous" else
4
47072
by: cindy liu | last post by:
Hi, In .Net, how to convert a string to a double? Thanks in advance! Cindy
1
320
by: faktujaa | last post by:
Hi, I have date in a string format like string strDate = "110204". Now i want to convert this string to MM/dd/yyyy format. How do i do this???? I used string.Format(strDate, "MM/dd/yyyy") but no effect. I guess i have to convert this to date and than to string(MM/dd/yyyy). Please help. Thanks in advance. faktujaa
2
2762
by: Nathan | last post by:
Is there a way to convert a string to a CipherMessage? I am calling a function that decrypts a CipherMessage and returns the value. The only problem is when I want to use an encrypted value stored in a querystring, I can't figure out how to convert it back to a CipherMessage.
0
1382
by: Toska | last post by:
Hi, Wonder how I can convert a string value to enum value. Code ------------------- <appSettings> <add key="BaseType" value="Sand" /> </appSettings>
9
8253
by: engteng | last post by:
How do I convert string to numeric in VB.NET 2003 ? Example convert P50001 to 50001 or 50001P to 50001 but if P is in middle then not convert. Regards, Tee
1
3868
by: adz1809 | last post by:
The title says it all, I need to converta string into a varialbe so that I can gain another value. here is the code so far: sub ValidateValues() DFData = "DatadField1,DatadField2,DatadField3,DatadField4,DatadField5" DFDataArry = split(DFData,",") DFTitle = "DF1Title,DF2Title,DF3Title,DF4Title,DF5Title" DFTitleArray = split(DFTitle,",")
1
2752
by: chaitukdr | last post by:
Hi, I tried to convert string value 1.10 to double like double val=convert.todouble("1.10"); only 1.1 is given as result instead of 1.10 plz suggest me with a proper answer
3
1912
by: NareshN | last post by:
Hi All, How to convert string value to int32. In timsplit i have value "17:00 - 2:00".Then i am converting it TimeIn and TimeOut.TimeIn is string now and how to convert it to int32.I am getting error while convertin Timesplit = strResultData.Split('-'); string TimeIn = Timesplit; string TimeOut = Timesplit; int TimeI = Int32.Parse(TimeIn);
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.