저는 C# 및 웹 서비스로 시작하는 초급 프로그래머입니다. 내 웹 서비스의 Service.cs
파일에서 XmlTextReader 사용
IService.cs
에서 만든 해당 속성 (DataMembers)에 배치하려고 오전
ReadXMLFile()
방법을 만들 파일.
제 문제는 기본적으로 내 코드가 아무 것도하지 않는다는 것입니다. 나는 이것에 웹 사이트 및 자습서를 찾는 시도했다 그러나 실제로 거기 밖으로 다량이 아니다, 특히 나 자신 같이 초심자를 위해. 내가 지금까지 해왔 던 일이 분명히 잘못 되었기 때문에 누구나 내가 어떻게해야하는지 알 수있다.
아래는 나의 ReadXMLFile()
방법입니다.
void ReadXMLFile()
{
XmlTextReader reader = new XmlTextReader("ClassRoll.xml");
reader.Read();
while (reader.Read())
{
if (reader.Name == "id")
{
id = reader.ReadString();
}
else if (reader.Name == "firstname")
{
link = reader.ReadString();
}
else if (reader.Name == "lastname")
{
description = reader.ReadString();
}
else if (reader.Name == "count")
{
description = reader.ReadString();
}
else if (reader.Name == "testscore")
{
description = reader.ReadString();
}
}
}
이
내 xml 파일의 예입니다<classroll>
<student>
<id>101010</id>
<lastname>Smith</lastname>
<firstname>Joe</firstname>
<testscores count="5">
<score>65</score>
<score>77</score>
<score>67</score>
<score>64</score>
<score>80</score>
</testscores>
</student>
</classroll>
} (http://stackoverflow.com/q/55828/1048330) – tenorsax
유용 당신은 당신의 XML 파일 또는 샘플을 공유해야 너무 크면 구조를 볼 수 있습니다. –
XmlTextReader를 직접 사용하면 안됩니다. 대신에'XmlReader.Create()'를 사용하십시오. –