Finding out if attribute X exists with XmlTextReader

My docs have attributes called "order", with a default value of 1. So if 
there is no "order" attribute, the program shall use the value 1. 
Implementing this with XmlTextReader was harder than expected. Since 
GetAttribute() returns null if the attribute isn't found, and null can 
be interpreted as false, I thought this would do it:

   decimal order = 1;
   if (r.GetAttribute("order"))
       order = Convert.ToDecimal(r.GetAttribute("order"));

I get the error:

   Cannot implicitly convert type 'string' to 'bool'

What's the right way to do it?

Gustaf
0
gustafl (18)
1/24/2006 7:53:08 PM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
451 Views

Similar Articles

[PageSpeed] 16

Gustaf,
The GetAttribute method returns the attribute as string value or null if no 
attribute exists.  The following should test this condition correctly.


String sAttr = r.GetAttribute("order");
if(sAttr != null)
{
    order = Convert.ToDecimal(sAttr);
}
else
{
    //do whatever you want when the attribute doesn't exist
}


Good luck...


"Gustaf" <gustafl@algonet.se> wrote in message 
news:eItwVASIGHA.3936@TK2MSFTNGP10.phx.gbl...
> My docs have attributes called "order", with a default value of 1. So if 
> there is no "order" attribute, the program shall use the value 1. 
> Implementing this with XmlTextReader was harder than expected. Since 
> GetAttribute() returns null if the attribute isn't found, and null can be 
> interpreted as false, I thought this would do it:
>
>   decimal order = 1;
>   if (r.GetAttribute("order"))
>       order = Convert.ToDecimal(r.GetAttribute("order"));
>
> I get the error:
>
>   Cannot implicitly convert type 'string' to 'bool'
>
> What's the right way to do it?
>
> Gustaf 


0
1/24/2006 8:34:41 PM
Reply:

Similar Artilces:

Need help with finding Amount
I need to look up the *Amount* based on two criteria (Provider and Date). Is there a built-in way to do that in Excel? Jan :) Where is the amount? Where is and what are the criteria? -- Biff Microsoft Excel MVP "Jan I" <abuse@localhost.invalid> wrote in message news:e6SuEIwyIHA.2184@TK2MSFTNGP02.phx.gbl... >I need to look up the *Amount* based on two criteria (Provider and Date). >Is there a built-in way to do that in Excel? > > Jan :) > > > Hi Biff, We have clients that buy sections of seats, much like a Ticket agent, and when the seats ...

Find and replace all
I use Office 2003 and I tried to do the following (and failed): I work in a spreadsheet with 1663 links to other resources ='C:\Documents and Settings\Pinnacle\Desktop\Pinnacle Spreadshee 1.0\24 Hour Mobility\[AlfaGranite.xls]SENNBV'!$O$4 Now I want to replace this whole directory link and I want to chang all the 1663 links from the long one (see above) to thi one='[AlfaGranite.xls]SENNBV'!$O$4 But I will not replace ='C:\Documents an Settings\Pinnacle\Desktop\Pinnacle Spreadsheet 1.0\24 Hour Mobility\ t '[AlfaGranite.xls]SENNBV'!$O$4 The cells are not protect...

Adding a new attribute to the GAL
Hi. We are wanting to add a new attribute to our GAL, and the only KB article from MS we found was removed from the MS site. I was wondering if anyone had done this, and what the repercussions were. I was also curious if anyone knew why the article may have been pulled. I'm guessing it means it is not a supported practice. Anyway, the article we found was: 313962 "How to modify Exchange 2000 or Exchange 2003 details templates" . Anyhelp would be great! Artie Noel dognoela@mailtest.nih.gov On Wed, 26 Jul 2006 11:45:59 -0400, Artie <noela@mail.nih.gov> wrote: &g...

Can't Find Macros
I have been messing around with check boxes and Visual Basic in my Control Toolbox. Somehow I've managed to imbed a macros in my workbook and am getting the warning message each time the file is opened. I can't seem to find the macros to delete it. I have 29 worksheets, so it's not an easy task. When I open my macros, there shows none. How can I find this and delete it? ALT + F11 to get to the Visual Basic Editor. Check for empty modules in your workbook. These, even though empty, must be removed. Check for Forms and delete. Also have a look through the sheets and Th...

Find name in subform using cbox and go to that record # in main fo
I have a customer entry form with linked sub form, one main customer name with multiple pets names (many) in the sub form. I realize you cant use the find button to search in the sub form. I have tried to use Allen's code to use the sub form table in a combo box but couldn't get it to work. I want be be able to choose the pet name using the combo box and then in the after update event, have the main form go to that record #. The [customer #] is the same in the main table and the sub table and that is what links them...[Cust #] in main, [Customer #] in sub table. How d...

new database file (mdb) created when an existing database is open
When I open an existing database and then close it a new mdb file is created in the same folder as the existing database. "salmosalar" <salmosalar@discussions.microsoft.com> wrote in message news:233AC696-203C-4258-8EA6-755F5FD6877F@microsoft.com... > When I open an existing database and then close it a new mdb file is > created > in the same folder as the existing database. You probably have compact on close set as an option, and don't have sufficient privileges on the folder, or you are shutting down too quickly and not allowing enough time for the com...

Find & Replace
Hello Guys: Excel 2000. I need to find a specific text, a flag (eg.: "<LineBreak>"), and replace it with a real manual line break . Is this something possible to do? Thanks, P. You could use a little macro that searches for that string, then inserts a pagebreak when it finds it. (I inserted a horizontal pagebreak.) Option Explicit Sub testme01() Dim myStr As String Dim FoundCell As Range myStr = "<LineBreak>" With ActiveSheet Do Set FoundCell = .Cells.Find(what:=myStr, _ afte...

Office X Registration
Hello, does anyone know how to tell if Office X is registered? Also, is it possible to change a product over to someone elses' name once it is registered? Thanks a lot! I don't know of a way to tell if a specific copy of Office has been registered. It doesn't really matter since registration is optional. Since the EULA allows one transfer of the software, yes, it is possible to change it over to someone else's name. That person can access the registration page if she/he wishes by going to "Online Registration" under the Entourage, Excel, Word, or PowerPoint menu....

Scaling the x-axis
Using a line chart, is it possible to have scaling appart from th Y-axis to the x-axis, regardless the kategory-values of the x axis? For example the values of x to establish some points are 5, 15, 30 etc is it possible to put them on scale as well on the chart? Thanks for your time! -- Message posted from http://www.ExcelForum.com Hi not quite sure but try using a X/Y scatter chart >-----Original Message----- >Using a line chart, is it possible to have scaling appart from the >Y-axis to the x-axis, regardless the kategory-values of the x axis? >For example the values of x to...

Excel Find Replace in batches
The standard Find & Replace tool in excel allows only a single item to replace another single item. I am looking for help on how to "batch" replace, i.e. replace all instances of January, February, March with Jan, Feb, Mar. I need to do this against thousands and thousands of entries. Does anyone have a way of referencing a "library" of master replacements and applying them to an immense worksheet of text values at once? ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from h...

X-axis labeling
I have been doing some analysis of reaction kinetics. The best way to plot the data is a rate versus inverse temperature. My issue is that 1/T is not a number that people that recieve my reports generally use, but temperature is. I'd like to label the x-axis with values for temperature. 1) Is there a way to plot X vs. Y and label an axis with Z instead of X? Alternatively, 2) Is there a way create a custom scale? I don't generally plot log(X). I usually just change the axis to log scale. Can I create a 1/X scale? Thanks! Steve Found my own answer at http://www.geocit...

X-Y scatter with names
I have 3 columns, let's say A, B, C Column A contains names (text information) Column B contains numeric values Column C contains numberic values I have made an X-Y scatter chart with X-axis values being that of column B and Y-axis values being that of column C. In the chart, for each data point that is shown, I would like to show its corresponding text values (from column A). Is there a way to achieve this and if so then how? Many thanks in anticipation. Hi, Try this free addin which links data labels to cell. http://www.appspro.com/Utilities/ChartLabeler.htm Cheers Andy -- ...

x.509 cert for TLS testing
Group, I have a CA on my test domain which I created an SSL cert for my OWA. Is it possible to 'roll your own' x.509 cert in order to test TLS for SMTP? I tried bit don't see the options to do so. If not, is there somewhere on the web to get one? Thanks, Mike Bonvie If you've installed a CA, you should be able to do it. If it's a non-enterprise CA (enterprise CAs are integrated with Active Directory), you can follow the same certificate request process that you would otherwsie follow for an external CA. Then copy the cert request file in the form on the CA web s...

Howto: Remove 2 x hard returns ...
Hi there, Outlook 2003 (11.6359.6408) SP1 Is there some place in Outlook I can set it not to insert 2 x hard return on the top of a new e-mail? I have created my own HTML signature and don't want the 2 x hard returns. Regards, Deon H ...

Publisher can't find Outlook
Both Outlook 2007 and Publisher 2007 are installed, Outlook is the only email- application in use. When I want to emerge a newsletter from Publisher to Outlook, it keeps telling me to install and configure Outlook 2007. I cannot find any solution to this problem. Can anyone help me? In Outlook, open help, look at the eighth entry. -- Mary Sauer http://msauer.mvps.org/ "Jannieke" <u49099@uwe> wrote in message news:90bada5a3a2a0@uwe... > Both Outlook 2007 and Publisher 2007 are installed, Outlook is the only email- > application in use. When I want to emerge a newslett...

bar charts with time-spaced x-axis?
does anyone know who to create bar charts where data is spaced on x-axis? currently i have time data on x-axis and quantity on the y. but the time data is evenly spaced rather than by the amount of time that has passed. in other words, i want events which occured 1 hour, 3 hours and 10 hours apart to be spaced accordingly on x-axis. anyone know how to do this? ------------------------------------------------ Message posted from the Excel Tip Forum at http://www.ExcelTip.com/forum/ -- View and post usenet messages directly from http://www.ExcelTip.com -- Hundreds of free MS Excel tips, ...

Adding element to xml with existing namespace ?
This is a multi-part message in MIME format. ------=_NextPart_000_0013_01C88530.27EFA3C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I have a generated xml (dbml) document that I have to add new elements = to.. here's an amended snippet.. <?xml version=3D"1.0" encoding=3D"utf-8"?> <Database Name=3D"mydb" EntityNamespace=3D"MyEntity" = ContextNamespace=3D"MyEntity" Class=3D"MyClass" = xmlns=3D"http://schemas.microsoft.com/linqtosql/dbml/2007"> <...

sorry, I could not find any host named <domain name> (#5.1.2)
I upgraded to Windows 2003 and Exchange 2003 over the weekend. Now, I can not send email to yahoo accounts and when sending from yahoo back, I get the above message. I do not have a "smarthost" setup and am running DNS on the exchange as well. I went to www.dnsreport.com and it says all is fine. Any ideas with what is going on with my SMTP? Setting wrong? TIA, Darrin hi darrin! either check your DNS snapin, in the properties of your dns server if you have set dns forwarders. use at least one external dns, e.g. the dns of your isp. or you open the properties of you smtp vir...

Scattered chart combined with columns and time-x-axis in XL2007
Dear Group, until XL2003 I could create a column chart, configure the x-axis to as a time-axis (for x-scaling purposes) and I could place scattered charts (as carrier for text and symbols) at any (non-integer) x-position. Using XL2007, scattered charts can only be positioned on x-integer-values. So I am forced to put a second transparent scattered-chart over the column-chart? Or is there any better way to do this in ONE chart? Thanks in advance: Holger. Ironically, the XY series can plot anywhere along a text axis in 2007. The first category is at X=1, the second at X=2, etc. I hadn...

Finding my product key
I have a copy of Publisher 2003, which I have installed on one computer and I would like to install it again. I have the disk but I can't find the case for it so I don't have the product code. How can I find out the number from the first computer to apply to the second computer. I think you may be SOL on this one. Unless the second computer is a laptop, you are not permitted to install it on an additional system. You'll need to contact Microsoft to obtain an additional product key if the installation is on a laptop. -- Ron "Don" <Don@discussions.microsoft.co...

bit attribute
I've created a custom bit attribute and I need to get the possible values a user would be able to select from through the api. For example, for a radio button with the values "Yes" or "No". I need to get the values "Yes and No". The bit attribute can be a radio button or a check box. For a picklist, i can get the data i need by accessing the PicklistAttributeMetadata. Assitance would be appreciated. Thanks..Steve G'day Steve!! I have some code that could help you there, however you could save yourself a lot of time if you know how to read the PICKLIST...

find and replace hyperlink?
Hi, I want to globally find and replace the contents of a hyperlink with a new hyperlink. For example, I want this Jul.xls#'Title Page'!A1 to be replaced with Aug.xls#'Title Page'!A1 I can't seem to find a way do it. Is there a way? Thank you, Mike Take a look at David McRitchie's site: http://www.mvps.org/dmcritchie/excel/buildtoc.htm look for: Fix Hyperlinks (#FixHyperlinks) If you're new to macros, you may want to read David McRitchie's intro at: http://www.mvps.org/dmcritchie/excel/getstarted.htm me wrote: > > Hi, I want to g...

format 3 X 5 individual postage paid reply cards
Help please. I need to create an rsvp card to enclose in an invitation. I'm using the postage paid cards purchased from the post office. I'll put my address on one side and the verbage requesting the rsvp on the other. Can't figure out how to do it on individual cards that I would load in my printer. The templates I've found are for a sheet of perforated cards. Appreciate any advice. You will need to define a custom page size, but there will be an issue of whether your printer can handle the individual cards. You may need to use one of the default page s...

present attributes instead of a name
Hello , Here is the code of the function I want to use: private TreeNode CreateTreeNodeFromXmlNode(XmlNode node) { TreeNode tmptreenode = new TreeNode(); if((node.HasChildNodes) && (node.FirstChild.Value != null)) { tmptreenode = new TreeNode(node.Name); TreeNode tmptreenode2 = new TreeNode(node.FirstChild.Value); tmptreenode.Nodes.Add(tmptreenode2); } else if(node.NodeType != XmlNodeType.CDATA) { tmptreenode = new TreeNode(node.Name); } return tmptreenode; } The problem is that insted of node.Name I want node.Attributes["name&...

how do I print onto 8.5 x 5.5 note cards
The paper size of the note cards that I want to print onto is not shown in the drop down box where you change paper size. How can I print onto this size? Setup your printer first for this size. Page setup should reflect the size and say it will print two copies per sheet on letter stock. If your stock is actually the size you stated, you will have to setup a custom size in your printer. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com http://officebeta.iponet.net/en-us/publisher/FX100649111033.aspx "S.Gipson" <S.Gips...