프로그래밍에 익숙합니다. 나는 XML 양식을 사용하여 XML 파일을 만들고 XML 파일의 이름은 Windows 양식의 이름 필드 텍스트 상자 텍스트입니다.이 파일은 이미 사용 가능하지만 새로운 이름을주고 싶지만 제공 할 수 있습니다. 다른 이름은 한 번만. 예를 들어 'dog.xml'이 이미 있으면 dog1.xml 파일을 만들 수 있습니다. 새 파일을 만들 때마다 'dog1.xml'파일의 내용이 새 파일 내용으로 바뀌지 만 ' 당신이 공상하고 마이크로 소프트의 표준을 준수하려는 경우 dog11.xml '또는'dog2.xml '파일XML을 만드는 동안 XML 파일에 동적 이름을 지정하는 방법
private void btnSave_Click(object sender, EventArgs e)
{
path = rtxtName.Text + ".xml";//name of a xml file is name of WPF 'name' field
doc = new XmlDocument(); //Here i am creating the xmldocument object
doc.CreateTextNode(path);
if (!System.IO.File.Exists(path))//if there is no file exists then
{
CreateNewXMLDoc();
}
else
{
path = rtxtName.Text + "1.xml"; //If the file is already avaliable
CreateNewXMLDoc();
}
}
public void CreateNewXMLDoc() //This method is for creating my xml file
{
XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
XmlComment comment = doc.CreateComment("This is a generated XML file");
doc.AppendChild(declaration);
doc.AppendChild(comment);
doc.AppendChild(doc.CreateElement("root"));
}
를 다시 시작할 때 당신이 정말로 문제가 XML과 관련이있다 생각하십니까 카운터를 계속 업데이트? –
이름을 변경하는 방법에 대한 코드가 제대로 작동합니다. 문제는 어디에 있습니까? –
내가 말할 수있는 한 something1.xml이 있으면 something2.xml로 저장할 수 있고, 처음 2 개가 있으면 something3.xml (실제로는 3 개, something.xml을 포함하는 경우)로 저장할 수 있기를 원합니다. – Johan