hi there, in VB LoadXML(str) returns true or false so that you can do
different coding when the str is XML or not, but in C# LoadXML doesn't have
return but only throw exception if str is not XML document. How would I do if
I want to do my own code if str is not an XML? thanks! 4 17813
cloudx <cl****@discuss ions.microsoft. com> wrote: hi there, in VB LoadXML(str) returns true or false so that you can do different coding when the str is XML or not, but in C# LoadXML doesn't have return but only throw exception if str is not XML document. How would I do if I want to do my own code if str is not an XML? thanks!
Anything wrong with catching the exception? It seems the simplest way
to me.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
If you start to parse the whole infoset to see if it is all valid xml, then
you may as well LoadXML as that what it does anyway. If you want a quick
check/guess, test to see if first char of string is "<". If not, you know
it is not xml. You don't know it is valid xml either, but the load will
tell you that. You may want to Trim() the string first just to remove any
leading or trailing spaces and test for Empty first, then for leading "<"
char.
--
William Stacey [MVP]
"cloudx" <cl****@discuss ions.microsoft. com> wrote in message
news:68******** *************** ***********@mic rosoft.com... hi there, in VB LoadXML(str) returns true or false so that you can do different coding when the str is XML or not, but in C# LoadXML doesn't have return but only throw exception if str is not XML document. How would I do if I want to do my own code if str is not an XML? thanks!
I am new to C# so I might be asking some silly questions. The issue is that
if the str is not XML then I would like to do something else instead of being
kicked out by exception. Thanks!
"Jon Skeet [C# MVP]" wrote: cloudx <cl****@discuss ions.microsoft. com> wrote: hi there, in VB LoadXML(str) returns true or false so that you can do different coding when the str is XML or not, but in C# LoadXML doesn't have return but only throw exception if str is not XML document. How would I do if I want to do my own code if str is not an XML? thanks!
Anything wrong with catching the exception? It seems the simplest way to me.
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Catching an Exception is not necessarily being "kicked out." While it's not
the most efficient way to handle an error, it certainly wouldn't be that
drastic. For example:
try
{
LoadXML(str);
... // do something with the XML
}
catch (XmlFormatExcep tion e)
{
// it wasn't XML if we get here, so do the other thing
}
finally
{
CloseXML();
}
/m
"cloudx" <cl****@discuss ions.microsoft. com> wrote in message
news:01******** *************** ***********@mic rosoft.com... I am new to C# so I might be asking some silly questions. The issue is that if the str is not XML then I would like to do something else instead of being kicked out by exception. Thanks!
"Jon Skeet [C# MVP]" wrote:
cloudx <cl****@discuss ions.microsoft. com> wrote: > hi there, in VB LoadXML(str) returns true or false so that you can do > different coding when the str is XML or not, but in C# LoadXML doesn't > have > return but only throw exception if str is not XML document. How would I > do if > I want to do my own code if str is not an XML? thanks!
Anything wrong with catching the exception? It seems the simplest way to me.
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Neil Schemenauer |
last post by:
python-dev@python.org.]
The PEP has been rewritten based on a suggestion by Guido to change
str() rather than adding a new built-in function. Based on my
testing, I believe the idea is feasible. It would be helpful if
people could test the patched Python with their own applications and
report any incompatibilities.
PEP: 349
|
by: Alex Vinokur |
last post by:
I have got two functions:
void foo1(char* str)
{
// Stuff
}
void foo2(int size)
{
char* str;
|
by: A.M |
last post by:
Hi,
Are string parameters in functions by refrence or by value ?
Thanks,
Ali
|
by: Bob |
last post by:
I'm having trouble the string.Format() throwing exceptions and I can't figure
out what I am doing wrong.
Given the following setup code:
string str = { "one", "two", "three", "four" };
double val = { 1.0, 2.0, 3.0, 4.0 };
string fmt = "{0} {1} {2} {3}";
The following variations of string.Format() will work just fine with strings:
string s1 = String.Format(fmt, str, str, str, str); // works
|
by: mrvendetta1 |
last post by:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 33
void StringToIntArray(const char *s1);
void takeinteger(int i);
int main()
{
char string;
printf("enter a string of bits no more than 32 bits long: ");
| |
by: zahy[dot]bnaya[At]gmail[dot]com |
last post by:
Hi,
I am trying to come up with a c style string reverser, I want it to
take 1 argument
Altough I would never do this in real life. Is there a way to do it?
I wrote this function that fails :
Any idea why it fails?
char * C_recReverse(char * str)
|
by: gagandeepgupta16 |
last post by:
I am having problem in parsing a string containing HTML Tags.
The situation is somewhat similar to the following as quoted in some other forum :
if (typeof DOMParser == "undefined") {
DOMParser = function () {}
DOMParser.prototype.parseFromString = function (str, contentType) {
if (typeof ActiveXObject != "undefined") {
var d =...
|
by: Christian Heimes |
last post by:
Gabriel Genellina schrieb:
Yes, it's on purpose but it's a bug in your application to call str() on
a bytes object or to compare bytes and unicode directly. Several months
ago I added a bytes warning option to Python. Start Python as "python
-bb" and try it again. ;)
Christian
|
by: JohnCox |
last post by:
I have a simple Win32 DLL I wrote named "SimpleLib" that exports two functions. It is written in C++ and compiled with __stdcall (/Gz) and with the preprocessor definition _MBCS (not Unicode).
The first function is called "StrFirst" and takes in a LPTSTR as the first parameter and a long as the second, like this:
SIMPLELIB_API int StrFirst(LPTSTR str, long num);
The second function is essentially the same thing, but with the order of the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |