내가 XML 파일이 있다고 가정하자 XML을 C#을에서 특정 속성을 인쇄하는 방법 :이 코드의 목적은 같은 LINQ를 사용하지 않고이 XML의 속성 캡션의 값을 읽을 필요가읽고
<?xml version="1.0" encoding="utf-8"?>
<Test Description="Test XML" VersionFormat="123" ProtectedContentText="(Test test)">
<Testapp>
<TestappA>
<A Id="0" Caption="Test 0" />
<A Id="1" Caption="Test 1" />
<A Id="2" Caption="Test 2" />
<A Id="3" Caption="Test 3">
<AA>
<B Id="4" Caption="Test 4" />
</AA>
</A>
</TestappA>
<AA>
<Reason Id="5" Caption="Test 5" />
<Reason Id="6" Caption="Test 6" />
<Reason Id="7" Caption="Test 7" />
</AA>
</Testapp>
</Test>
을 Unity3D에서 이것을 수행하십시오.이 코드를 작성하기 위해 밤새도록 보낸 후에 작동하지 않는 코드를 작성하십시오. 도와주세요!
코드 냈다 : 우리는 몇 가지 옵션이 특성을 잡아 내 XML 그런
XmlDocument x = new XmlDocument();
x.Load("Filename goes here");
와 우선 하중을 XmlDocument :
// XML settings
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
settings.IgnoreComments = true;
// Loop through the XML to get all text from the right attributes
using (XmlReader reader = XmlReader.Create(sourceFilepathTb.Text, settings))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.HasAttributes)
{
if (reader.GetAttribute("Caption") != null)
{
MessageBox.Show(reader.GetAttribute("Caption"));
}
}
}
}
}