Skip to content

Instantly share code, notes, and snippets.

@usausa
Created October 7, 2020 12:38
Show Gist options
  • Save usausa/0bba9402faf04ea2aca4f4191d00a91f to your computer and use it in GitHub Desktop.
Save usausa/0bba9402faf04ea2aca4f4191d00a91f to your computer and use it in GitHub Desktop.
XmlReaderExtensions
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>内の要素の処理
}
}
}
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