내 XML 파일을 읽으려고하면 두 번 읽히고 이러한 오류를 수정하는 방법이 확실하지 않습니다. 나는 어떤 종류의 고리를 가질 수 있다고 생각했지만 아직도 잃어버린 메신저. 어떤 도움을 주셔서 감사합니다. - xml 파일을 올바르게 기록하지만 읽으면 복제가 발생합니다.xml 파일을 읽을 때 노드의 복사본을 읽습니다.
String workingDir = Directory.GetCurrentDirectory();
XmlTextReader textReader = new XmlTextReader(workingDir + @"\xmldoc.xml");
Console.WriteLine("BaseURI:" + textReader.BaseURI);
textReader.Read();
while (textReader.Read())
{
if (textReader.Name == "test")
{
textReader.Read();
XmlNodeType nType = textReader.NodeType;
if (nType == XmlNodeType.Text)
{
// label.Text = textReader.Value.ToString();
Label l = new Label();
System.Drawing.Point l1 = new System.Drawing.Point(15, 13 + a);
l.Location = l1;
l.Text = textReader.Value.ToString();
a += 20;
}
어떻게 관찰 했나요? '두 번 읽는 것 같습니다.' – sll
중요한 데이터가 아닌 경우 읽을 XML 샘플을 게시 할 수 있습니까? 무슨 일이 일어나고 있는지 파악하는 데 도움이 될 수 있습니다. 또한, 거대한 입력을 기대하지 않는다면 XmlDocument (또는 LINQ-y를 사용하는 경우 XDocument)를 사용하는 것이 더 직관적 일 수 있습니다. 나는 항상 XmlReader가 더러운 코드로 이어진다는 것을 안다. – LexyStardust
참고로, 당신은'new XmlTextReader()'를 사용하면 안된다. .NET 2.0 이후로는 사용되지 않습니다. 대신에'XmlReader.Create()'를 사용하십시오. –