를 교체합니다. 이 속성은 모든 곳에서 발생할 수 있습니다. 이미의 가치를 찾을 수있는 그 ID의나는이와 비슷한 구조를 포함하는 XML 문서와 함께 일하고 있어요 XML의 속성 값 (attrubute 경로 변수)
XmlTextReader reader = new XmlTextReader(@"Main.xml");
while (reader.Read())
{
reader.MoveToContent();
string test = reader.GetAttribute("ID");
if (test == "$")
{
MessageBox.Show(test);
}
}
하지만 변경할 수 없습니다. 목표 : 어디서나 ID를 찾고 해당 attibute의 값을 '값'으로 바꿉니다.
누가 나를 도울 수 있습니까? 나는 이미 Xdocument와 Xmldocument도 시도했다. 나는 그것을 이해할 수 없다. XML을 LINQ 나는 당신은 당신의 문서를로드 XmlDocument
및
XPathNavigator
을 사용하고 XPath를 사용하여 위로 이동하고 당신이 필요로하는 값을 변경하는 것이 더 쉽습니다 생각
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication13
{
class Program
{
const string FILENAME = @"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
List<XElement> ids = doc.Descendants().Where(x => x.Attribute("ID") != null).ToList();
int indNo = 1;
foreach (XElement id in ids)
{
id.Attribute("ID").SetValue(indNo++);
}
}
}
}
감사합니다 들어
. 이 솔루션은 나를 위해 작동합니다! –