<Root>
<Application>
<AppName>App1</AppName>
<IdMark>ClassName</IdMark>
<ClassName>Notepad</ClassName>
<ExecName>Notepad</ExecName>
<Mod>
<ModName>HookPrintAPIs</ModName>
<Api>
<ApiName>TextOutA</ApiName>
<ApiName>TextOutW</ApiName>
<ApiName>ExtTextOutA</ApiName>
<ApiName>ExtTextOutW</ApiName>
<ApiName>DrawTextA</ApiName>
<ApiName>DrawTextW</ApiName>
<ApiName>DrawTextExA</ApiName>
<ApiName>DrawTextExW</ApiName>
<ApiName>GdiDrawString</ApiName>
</Api>
</Mod>
</Application>
</Root>
j'ai un fichier xml je veux analyser ce x, fichier l et que vous souhaitez stocker dans un objet comment il est possibleproblème d'analyse syntaxique xml en C#
j'ai utilisé la technique d'analyse syntaxique comme ce
ArrayList oArrayListForModuleName = new ArrayList();
ArrayList oArrayListClass = new ArrayList();
ArrayList oArrayListApi = new ArrayList();
List<string> oListofApiName1 = new List<string>();
while (oRreader.Read())
{
if (oRreader.NodeType == XmlNodeType.Element)
{
switch (oRreader.Name)
{
case "AppName":
oRreader.Read();
oArrayListClass.Add(oRreader.Value);
break;
case "IdMark":
oRreader.Read();
oArrayListClass.Add(oRreader.Value);
break;
case "ClassName":
oRreader.Read();
oArrayListClass.Add(oRreader.Value);
break;
case "ExecName":
oRreader.Read();
oArrayListClass.Add(oRreader.Value);
break;
case "ModName":
oRreader.Read();
oArrayListForModuleName.Add(oRreader.Value);
break;
case "ApiName":
oRreader.Read();
oArrayListApi.Add(oRreader.Value);
oListofApiName1.Add(oRreader.Value);
break;
}
}
}
oRreader.Close();
for (int i = 0; i < oArrayListApi.Count; i++)
{
if (oArrayListApi[i].Equals("Not Set"))
{
oArrayListApi[i] = "";
}
}
for (int i = 0; i < oArrayListForModuleName.Count; i++)
{
if (oArrayListForModuleName[i].Equals("Not Set"))
{
oArrayListForModuleName[i] = "";
}
}
int counter = 0;
int countformod = 0;
while (j < oArrayListClass.Count)
{
CConfigManager oXmlHook = new CConfigManager();
oXmlHook.uAppName = oArrayListClass[j].ToString();
oXmlHook.uIdMark = oArrayListClass[++j].ToString();
oXmlHook.uClassName = oArrayListClass[++j].ToString();
oXmlHook.uExecName = oArrayListClass[++j].ToString();
for (int cntr = 0; cntr < countofapi; cntr++)
{
oXmlHook.oListOfApiName.Add(oArrayListApi[counter].ToString());
counter++;
}
for (int c = 0; c < countofmodule; c++)
{
oXmlHook.oListOfModuleName.Add(oArrayListForModuleName[countformod].ToString());
countformod++;
}
oArrListOfObject.Add(oXmlHook);
j++;
}
J'utiliserais XmlDocument ou XElement au lieu d'analyser manuellement - si vous ne pouvez pas les utiliser, vous pouvez expliquer pourquoi. –