.net XML属性更新

.net XML属性更新,.net,xml,powershell,attributes,.net,Xml,Powershell,Attributes,我有一个类似于以下内容的XML: <?xml version="1.0" encoding="utf-8"?> <Configuration> <Format_Version>1.0</Format_Version> <Reporting> </Reporting> <Jobs> <!--<Job> <Name>Spac

我有一个类似于以下内容的XML:

<?xml version="1.0" encoding="utf-8"?>
<Configuration>
  <Format_Version>1.0</Format_Version>
  <Reporting>
  </Reporting>
  <Jobs>
        <!--<Job>
                <Name>SpaceCheck</Name>
                <Job_Type>SpaceCheck</Job_Type>
                <Schedule>
                    <Start_Time>0300</Start_Time>
                    <Frequency>24 hours</Frequency>
                    <Max_Run_Time_In_Seconds>10</Max_Run_Time_In_Seconds>
                </Schedule>
                <Parameters>
                    <Drive>C</Drive>
                    <Drive>D</Drive>
                </Parameters>
        </Job>
        <Job>
                <Name>CPUCheck</Name>
                <Job_Type>UsageMonitor</Job_Type>
                <Schedule>
                    <Frequency>3 minutes</Frequency>
                </Schedule>
                <Parameters>
                    <Threshold>90%</Threshold>
                    <Duration>10 minutes</Duration>
                </Parameters>
        </Job>
        <Job>
                <Name>overloaded CPUCheck</Name>
                <Job_Type>CPUcheck2</Job_Type>
                <Schedule>
                    <Frequency>3 minutes</Frequency>
                </Schedule>
                <Parameters>
                    <Threshold>80%</Threshold>
                    <Duration>50 minutes</Duration>
                </Parameters>
            </Job>-->
        <Job>
          <Name>Connection</Name>
          <Job_Type>Connectivity</Job_Type>
          <Schedule>
            <Start_Time>1900</Start_Time>
            <Frequency>1</Frequency>
            <Maximum_Runtime>30</Maximum_Runtime>
          </Schedule>
          <Parameters>
            <ToErrInHours>1</ToErrInHours>
            <Days>1</Days>
            <Threshold>70</Threshold>
          </Parameters>
        </Job>
      </Jobs>
    </Configuration>

您试图通过调用
SetAttribute()
将1900更改为2300,但是1900不是元素的属性。您应该改为设置
InnerText
,如下所示:

$StartTime.InnerText = "2300"
MSDN中的一个示例。它使用以下内容作为示例XML。请注意
与要更改的
元素是多么相似

<?xml version="1.0" encoding="utf-8"?>
<books xmlns="http://www.contoso.com/books">
  <book genre="novel" ISBN="1-861001-57-8" publicationdate="1823-01-28">
    <title>Pride And Prejudice</title>
    <price>24.95</price>
  </book>
  <book genre="novel" ISBN="1-861002-30-1" publicationdate="1985-01-01">
    <title>The Handmaid's Tale</title>
    <price>29.95</price>
  </book>
  <book genre="novel" ISBN="1-861001-45-3" publicationdate="1811-01-01">
    <title>Sense and Sensibility</title>
    <price>19.95</price>
  </book>
</books>

非常感谢您的修复-这确实有效,而且我的XML文档已经更新。很抱歉,这是一个完全无意的错误-意外地单击了向下箭头。
<?xml version="1.0" encoding="utf-8"?>
<books xmlns="http://www.contoso.com/books">
  <book genre="novel" ISBN="1-861001-57-8" publicationdate="1823-01-28">
    <title>Pride And Prejudice</title>
    <price>24.95</price>
  </book>
  <book genre="novel" ISBN="1-861002-30-1" publicationdate="1985-01-01">
    <title>The Handmaid's Tale</title>
    <price>29.95</price>
  </book>
  <book genre="novel" ISBN="1-861001-45-3" publicationdate="1811-01-01">
    <title>Sense and Sensibility</title>
    <price>19.95</price>
  </book>
</books>
public void editBook(string title, string ISBN, string publicationDate,
    string genre, string price, XmlNode book, bool validateNode, bool generateSchema)
{

    XmlElement bookElement = (XmlElement)book;

    // Get the attributes of a book.        
    bookElement.SetAttribute("ISBN", ISBN);
    bookElement.SetAttribute("genre", genre);
    bookElement.SetAttribute("publicationdate", publicationDate);

    // Get the values of child elements of a book.
    bookElement["title"].InnerText = title;
    bookElement["price"].InnerText = price;

    if (validateNode)
    {
        validateXML(generateSchema, bookElement.OwnerDocument);
    }
}