Click here to Skip to main content
15,881,650 members
Home / Discussions / C#
   

C#

 
AnswerRe: Same void between multiple forms in the same project? Pin
OriginalGriff17-May-23 7:54
mveOriginalGriff17-May-23 7:54 
QuestionFunc<> Question Pin
Kevin Marois3-May-23 18:48
professionalKevin Marois3-May-23 18:48 
AnswerRe: Func<> Question Pin
Richard Deeming3-May-23 21:47
mveRichard Deeming3-May-23 21:47 
GeneralRe: Func<> Question Pin
Kevin Marois4-May-23 5:57
professionalKevin Marois4-May-23 5:57 
SuggestionRe: Func<> Question Pin
BillWoodruff26-May-23 19:56
professionalBillWoodruff26-May-23 19:56 
QuestionXML validation with Schematron Pin
antann781-May-23 0:56
antann781-May-23 0:56 
AnswerRe: XML validation with Schematron Pin
jschell1-May-23 11:21
jschell1-May-23 11:21 
QuestionHow to "Reach" content of an XML node/tag (and turn it into a new reader) Pin
pr1mem0ver20-Apr-23 3:30
pr1mem0ver20-Apr-23 3:30 
I have a project that will end up language dependent. I am also fairly new to XML in terms of reading it from files. I need to use XML for information used by the project and that information will be available in several languages. So the basic structure of the XML is this:

XML
<InfoNode>
    <Language ID="enUS">
        <DataClassNode>
            <Name>SomeName</Name>
            <Abbrev>SN</Abbrev>
            <Description>Some Description of what this represents</Description>
        </DataClassNode>
    </Language>
</InfoNode>


The code that does this and then the code that deserializes the information is this:
C#
public static DataClassNode Deserialize(XmlReader reader, CultureInfo culturalLanguage)
{
	XmlReader found = null;
	XmlReader _default = null;
	while (found == null)
	{
		if (reader.ReadToFollowing("Language"))
		{
			if (reader.MoveToAttribute("ID"))
			{
				string id = reader.ReadContentAsString();
				reader.MoveToElement(); // Is this how I get to the contents of the language node?
				if (id.Equals(culturalLanguage.Name))
				{
					// not sure how to read the contents of the node
					found = XmlReader.Create(reader.ReadElementContentAsString()); // throws exception 
																					//  'Element' is an 
																					//	invalid XML Node Type
				}
				else if (id.Equals(DefaultCulture.Name))
				{
					_default = XmlReader.Create(reader.ReadInnerXml().ToStream());
				}
			}
		}
		else
			break;
	}
	if (found == null)
	{
		if (_default == null)
			throw new Exception("Default Language Not Found!");
		else
			found = _default;
	}

	DataContractSerializer serializer = new DataContractSerializer(typeof(DataClassNode));
	DataClassNode flagtag = (DataClassNode)serializer.ReadObject(found);
	if (flagtag == null)
		throw new Exception("Cannot deserialize DataClassNode Object!");
	return flagtag;
}


I have been able to navigate to the language and make sure the one needed is found. Now I need to populate a class instance with the data inside the language node. I am using DataContractSerializer so I want a new XMLreader instance that contains the content of the language node ONLY. Not sure how to do this though. I know how to read strings etc... just not sure how to read the contents of the language node. I have tried what is above. I have tried InnerXML and OuterXML. Both of these return "None" as my XML. My comments point to where my knowledge falls short.

modified 20-Apr-23 10:00am.

AnswerRe: How to "Reach" content of an XML node/tag (and turn it into a new reader) Pin
Gerry Schmitz22-Apr-23 5:34
mveGerry Schmitz22-Apr-23 5:34 
AnswerRe: How to "Reach" content of an XML node/tag (and turn it into a new reader) Pin
lmoelleb24-Apr-23 5:18
lmoelleb24-Apr-23 5:18 
GeneralRe: How to "Reach" content of an XML node/tag (and turn it into a new reader) Pin
pr1mem0ver7-Jul-23 22:46
pr1mem0ver7-Jul-23 22:46 
Question405 Error for WebSocket with WSS but not WS (ASP.Net) Pin
Gwyll14-Apr-23 4:20
Gwyll14-Apr-23 4:20 
AnswerRe: 405 Error for WebSocket with WSS but not WS (ASP.Net) Pin
OriginalGriff14-Apr-23 6:00
mveOriginalGriff14-Apr-23 6:00 
GeneralRe: 405 Error for WebSocket with WSS but not WS (ASP.Net) Pin
Gwyll14-Apr-23 7:53
Gwyll14-Apr-23 7:53 
GeneralRe: 405 Error for WebSocket with WSS but not WS (ASP.Net) Pin
jschell14-Apr-23 11:38
jschell14-Apr-23 11:38 
AnswerRe: 405 Error for WebSocket with WSS but not WS (ASP.Net) Pin
Gwyll14-Apr-23 12:43
Gwyll14-Apr-23 12:43 
QuestionHow to get XSI:type in inner class while converting to XML Pin
dineshrastogi14-Apr-23 1:42
dineshrastogi14-Apr-23 1:42 
AnswerRe: How to get XSI:type in inner class while converting to XML Pin
Pete O'Hanlon14-Apr-23 2:05
mvePete O'Hanlon14-Apr-23 2:05 
QuestionC# List of Tasks Pin
Kevin Marois6-Apr-23 19:07
professionalKevin Marois6-Apr-23 19:07 
AnswerRe: C# List of Tasks Pin
OriginalGriff6-Apr-23 19:15
mveOriginalGriff6-Apr-23 19:15 
GeneralRe: C# List of Tasks Pin
Kevin Marois6-Apr-23 19:45
professionalKevin Marois6-Apr-23 19:45 
GeneralRe: C# List of Tasks Pin
OriginalGriff6-Apr-23 20:21
mveOriginalGriff6-Apr-23 20:21 
GeneralRe: C# List of Tasks Pin
Kevin Marois6-Apr-23 20:22
professionalKevin Marois6-Apr-23 20:22 
GeneralRe: C# List of Tasks Pin
OriginalGriff6-Apr-23 21:50
mveOriginalGriff6-Apr-23 21:50 
GeneralRe: C# List of Tasks Pin
OriginalGriff6-Apr-23 21:58
mveOriginalGriff6-Apr-23 21:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.