IT

XElement를 통해 속성을 넣는 방법

lottoking 2020. 7. 13. 07:50
반응형

XElement를 통해 속성을 넣는 방법


이 코드가 있습니다.

XElement EcnAdminConf = new XElement("Type",
                    new XElement("Connections",
                        new XElement("Conn"),
                    // Conn.SetAttributeValue("Server", comboBox1.Text);
                    //Conn.SetAttributeValue("DataBase", comboBox2.Text))),
                    new XElement("UDLFiles")));
                    //Conn.

Conn에 속성을 넣는 방법? 주석으로 표시 한이 속성을 그래서 싶지만 정의 후 속성을 Conn으로 설정 하려고 하면 속성 EcnAdminConf을 ... XML 다음과 같이 보이게하기 위해 어떻게 든 설정하고 싶습니다.

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

XAttribute의 생성자에 다음 XElement과 같이 추가하십시오 .

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

생성을 통해 여러 속성 또는 요소를 추가 할 수도 있습니다.

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

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

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

참고 URL : https://stackoverflow.com/questions/5063936/how-to-put-attributes-via-xelement

반응형