|
"[Select]"
A regex can be anything you like, that is, there are many ways to match that string. The real question is, how closely do you need to match it, and what other strings would be OK ? Expresso is a tool you should download to help you learn regex
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
What string do you want to validate for what values?
This ^ gave me loads of answers in seconds.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hello everyone,
I need to generate some XML message, but the message can not be reflected from members or properties of class instance directly.
Currently, I am using StringBuilder to append strings into XML message manually (e.g. to generate the element's hierarchies and add attributes to element), I think this method is stupid.
Any better approaches recommended?
thanks in advance,
George
|
|
|
|
|
XMLDocument can be better than StringBuilder...
|
|
|
|
|
Thanks natsuyaki,
1.
I read some documents for XMLDocument and XMLElement, looks like we need to use DOM model, right?
2.
I have not found some good samples for a beginner, I have XML knowledge before and just want to learn how to use the C# classes. Any referred samples?
regards,
George
|
|
|
|
|
George_George wrote: looks like we need to use DOM model, right?
Yes. XMLDocument use DOM. When file is loaded, it loads the entire file into memory. So if the file is very large, this method is inefficient. Calling Save() method on this class instance will save all the changes made to the instance.
George_George wrote: Any referred samples?
I think MSDN has enough documentation on using these classes. It's pretty easy.
|
|
|
|
|
Thanks N a v a n e e t h,
XMLTextWriter will not use DOM model and only loads necessary nodes other than all nodes (which is done in DOM model)?
regards,
George
|
|
|
|
|
George_George wrote: XMLTextWriter will not use DOM model and only loads necessary nodes other than all nodes
XMLTextWriter won't load any nodes. It is used to create XML documents. It has some methods which you can use to create nodes, attributes etc.
|
|
|
|
|
Sorry, N a v a n e e t h!
My bad, I mean XMLTextReader, it will not load the entire tree as DOM, like XMLDocument, and it will only loads necessary nodes, right?
regards,
George
|
|
|
|
|
Yes. It will not load the full file initially. XMLDocument class is also using a reader internally to fill the data.
|
|
|
|
|
Thanks N a v a n e e t h,
1.
So, can I understand that using XMLDocument has better performance compared with XMLTextReader, but bigger memory footprint.
2.
XMLDocument can both read/write, but XMLTextReader can only read, and XMLTextWriter can only write?
regards,
George
|
|
|
|
|
George_George wrote: So, can I understand that using XMLDocument has better performance compared with XMLTextReader, but bigger memory footprint.
This depends on the XML file size. When you call Load() method in an XMLDocument classes instance, it reads all the nodes and forms a DOM and keeps in the memory. So when the file is huge, it will consume more memory.
Performance is dependent of your scenario. If you need to read the XMLFile (not as DOM), XMLTextReader will give good performance. For creating a new xml file, XMLTextWriter will give good performance. Say, in a situation where you will add new nodes, change the attributes, and doing some XPath queries, then better choice would be XMLDocument class.
George_George wrote: XMLDocument can both read/write, but XMLTextReader can only read, and XMLTextWriter can only write?
XMLDocument class can do more than read/write. It supports XPath queries also.
|
|
|
|
|
Great N a v a n e e t h!
If I only need to read XML documents (in a file) into memory and get some values for some elements, then I think using XMLDocument will always have better performance, since all nodes are in memory (compared with XMLTextReader, only parts of nodes are in memory). Why do you think it is not always true?
regards,
George
|
|
|
|
|
George_George wrote: If I only need to read XML documents (in a file) into memory and get some values for some elements, then I think using XMLDocument will always have better performance
If the file size is less, you won't find any performance differences. XMLDocument provides an easy way to load and edit data. You can go with any methods which really suits your scenario.
|
|
|
|
|
Thanks N a v a n e e t h,
If the size of file is big, using XMLDocument is of better performance?
regards,
George
|
|
|
|
|
You can use XMLTextWriter or XMLDocument . XMLTextWriter will be faster.
|
|
|
|
|
|
If your using .NET 3.5
Try to use XElement using System.Xml.Linq
its pretty easy, fast and convinient when compared to DOM
Regards,
Vythees
Miles to go before sleep...
|
|
|
|
|
Thanks Vythees,
I need to use .Net 2.0 in current project, do you have any suggestions?
regards,
George
|
|
|
|
|
Go for XMLDocument since its easy to maintain, futuristic, and supports XPath queries.
Regards,
Vythees
Miles to go before sleep...
|
|
|
|
|
Thanks Vythees,
What do you think the pros and cons compared with XMLDocument and XMLTextWriter from functional and performance perspective?
regards,
George
|
|
|
|
|
Hello everyone,
When dealing with value types, I met with two conflicting points,
1. We can not inherit one value type from another, for example, we can not make a struct inherit from another struct; -- I think it means there is no inheritance or derivation for value types.
2. All value types are inherits from ValueType, and ValueType is inherits from Object, seems value types could have inheritance or derivation?
How do you understand the two conflicting points?
thanks in advance,
George
|
|
|
|
|
I haven tested it but Id guess that the restriction is in C#
While it might perfectly possible to inherit valuetypes in CIL code
There are other similair things you might find.
Eg delegates seems to be some sort of beast of their own in C#.
But in CIL they are just classes that derive from delegate..
|
|
|
|
|
Thanks Roger,
1.
Roger Alsing wrote: that the restriction is in C#
You mean the restriction is we can not derive one struct from another?
2.
Roger Alsing wrote: beast of their own in C#.
Why do you think delegate is beast of C#?
regards,
George
|
|
|
|
|
because it is simply a language construct (a C# one) that hides CIL details (i.e. standard class derivation and so on...). If I remember well, Andrew Troelsen calls it 'syntactic sugar'.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|