Browsing 7239 questions and answers with Jon Skeet

c# XDocument issue

I am quite new to xml-parsing. Following very basic tutorials I try to parse the following xml returned by a CalDav server: <?xml version="1.0" encoding="utf-8"...
Jon Skeet
people
quotationmark

Your response element is actually in a namespace, due to this attribute in the root node: xmlns="DAV:" That sets the default namespace for that element and its descendants. So you need to search for elements in that namespace too.... more 6/12/2015 12:13:21 PM

people

C# Unusual xml parsing

I have to parse one xml file to another, strictly defined one. The original file looks something like this: <Data> <Client> <id>ID1</id> ...
Jon Skeet
people
quotationmark

I would strongly recommend using LINQ to XML instead of XPath for this. (You can use XPath, certainly - but it's less readable IMO. You'd just need to use ClientNodes[i].SelectNodes("Details").) var xml = XDocument.Load(...); foreach (var... more 6/12/2015 10:22:50 AM

people

out parameter assigned by passing it to another function as an out parameter

I wrote a Tree structure and then made a static function to try to parse a Tree from a source file. public static bool TryParseTreeFromFile(String filePath, out Tree tree) { ...
Jon Skeet
people
quotationmark

The problem is that you're only conditionally calling CreateTree. Suppose parsingIsTotal is false - then this expression: parsingIsTotal && CreateTree(...) will evaluate the left hand operand, find that it's false, and not... more 6/12/2015 7:15:55 AM

people

How to return value from the method in C#

It might be a small question, but i am not understanding why it is throwing error. Error: Use of unassigned local variable status. public static bool...
Jon Skeet
people
quotationmark

There are two problems here: 1) You've declared a local variable a static. That's invalid. 2) If an exception is thrown early in your method, you're catching it and then trying to return status without ever assigning a value to it. I... more 6/12/2015 7:12:01 AM

people

Coverting String to LocalTime with/without nanoOfSeconds

I need to convert a string to LocalTime (java-8 not joda) that may or maynot have nanoOfSeconds in the string. The String format is in the form of 07:06:05 or 07:06:05.123456...
Jon Skeet
people
quotationmark

You could use "optional sections" of the format pattern for this: DateTimeFormatter dtf = DateTimeFormatter.ofPattern("H:mm:ss[.SSSSSS]"); more 6/11/2015 6:15:18 PM

people

Set LocalTime joda

How to set required timezone in LocalTime from joda? Required timezone - Moscow. Default constructor new LocalTime() shows other time for me: it shows time, which is one hour...
Jon Skeet
people
quotationmark

A LocalTime doesn't have a time zone. That's the whole point of it. If you want the LocalTime for a particular instant in a particular time zone, you can use DateTime and then toLocalTime: DateTime now = new DateTime(zone); // Urgh: see... more 6/11/2015 4:38:45 PM

people

Get those elements from a List of custom class objects whose one property value is parseable to double

I have a list of custom class objects in C# with class structure like this: public class ABC { int ID; string Text1; string Text2; } This list stores data like...
Jon Skeet
people
quotationmark

You can use double.TryParse within LINQ, although admittedly the out parameter is annoying: ABCObject = ABCObject .Where(x => { double ignored; return double.TryParse(x => x.Text2, out ignored); } .GroupBy(c => c.ID) ... more 6/11/2015 4:35:06 PM

people

Attempting to use SHA1 hashing to send password to Google

I am currently working on a program with Google's Directory API to reset the password of someone in my domain. I have it all working, but I would like to send an encrypted...
Jon Skeet
people
quotationmark

(Disclaimer: I work for Google, but I haven't looked at this API before.) Well, the problem when you call password.ToString() is that it's not providing the hex representation - so that's why the first piece of code fails. It looks like... more 6/11/2015 4:07:31 PM

people

why use protocol buffers in java

Recently,I read code of HBase.I find client use protobuf to communicate with server in HBase's code. Java has "Serializable". why not use it?
Jon Skeet
people
quotationmark

Efficiency: protocol buffers are generally much more efficient at transmitting the same amount of data than Java binary serialization Portability: Java binary serialization is not widely implemented outside Java, as far as I'm aware... more 6/11/2015 2:58:36 PM

people

Why final Byte as a case in switch statement doesn't compile?

byte a = 125; final byte b = 2; final Byte c = 3; switch (a) { case b: // works fine break; case c: // Constant Expression required break; } Since cis a final variable,...
Jon Skeet
people
quotationmark

Since c is a final variable, isn't it a compile time constant No. The rules for constant expressions are given in JLS 15.28, and they don't include wrapper types: A constant expression is an expression denoting a value of... more 6/11/2015 1:41:51 PM

people