2011-02-21 3 views
93

를 통해 속성을 넣어? 주석으로 표시 한이 속성을 넣으려고합니다. 그러나 EcnAdminConf을 정의한 후 Conn에 특성을 설정하려고하면 Visibe가 아닙니다 ... 그래서 XML을 어떻게 든 설정하여 XML이 다음과 같이 보이기 시작합니다.어떻게이 코드가 XElement를

<Type> 
    <Connections> 
     <Conn ServerName="FAXSERVER\SQLEXPRESS" DataBase="SPM_483000" /> 
     <Conn ServerName="FAXSERVER\SQLEXPRESS" DataBase="SPM_483000" /> 
    </Connections> 
    <UDLFiles /> 
    </Type> 

답변

202

또한 생성자

new XElement("Conn", new XAttribute("Server", comboBox1.Text), new XAttribute("Database", combobox2.Text)); 
을 통해 여러 속성이나 요소를 추가 할 수 있습니다

new XElement("Conn", new XAttribute("Server", comboBox1.Text)); 

처럼 XElement의 생성자에서 XAttribute 추가

또는 의 추가 방법을 사용하여 속성을 추가 할 수 있습니다.

XElement element = new XElement("Conn"); 
XAttribute attribute = new XAttribute("Server", comboBox1.Text); 
element.Add(attribute); 
관련 문제