Created
October 7, 2020 12:38
-
-
Save usausa/0bba9402faf04ea2aca4f4191d00a91f to your computer and use it in GitHub Desktop.
XmlReaderExtensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!reader.MoveToNextElement(0) || (reader.Name != "Root")) | |
{ | |
return; | |
} | |
while (reader.MoveToNextElement(1)) | |
{ | |
if (reader.Name == "Group1") | |
{ | |
while (reader.MoveToNextElement(2)) | |
{ | |
// <Root><Group1>...</Group1></Root>内の要素の処理 | |
} | |
} | |
else if (reader.Name == "Group2") | |
{ | |
while (reader.MoveToNextElement(2)) | |
{ | |
// <Root><Group2>...</Group2></Root>内の要素の処理 | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class XmlReaderExtensions | |
{ | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public static bool MoveToNextElement(this XmlReader reader, int depth) | |
{ | |
while (reader.Read()) | |
{ | |
if ((reader.NodeType == XmlNodeType.Element) && (reader.Depth == depth)) | |
{ | |
return true; | |
} | |
if (reader.Depth < depth) | |
{ | |
return false; | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment