我有一个包含三个节点的现有节点列表。他们的价值观是这样的:
exixtingNods= childIP childPort childSecure childProxyId ------- -------- ----------- ------------ 1.1.1.1 8888 true 1 1.1.1.2 8886 true 2 1.1.1.3 8888 true 3 dataobject childIP childPort childSecure childProxyId ------- -------- ----------- ------------ 1.1.1.1 8888 true 1
代码:
#include <string>
struct Name {
std::string fname;
std::string lname;
};
struct Info {
int grade;
std::string phone;
};
struct Mark {
int math;
int sci;
int eng;
};
struct Student {
Name n;
Info i;
Mark m;
};
int main()
{
Student class_list[MAX_CLASS_SIZE] = {
{ {"Bob", "Smith"}, {11, "519-688-5168"}, {88, 75, 78} }
};
}
使用以上代码,我试图基于$existingNods = $xmlData.SelectNodes("//parent/childInfo/child")
if ([string]::IsNullOrEmpty($existingNods)) {
Write-Host "created childInfo for ******************** "$dataObject.childIP
$childProxyInfo = $xmlData.CreateElement("dakotaProxyInfo")
$childIP = $xmlData.CreateElement("childIP")
$childPort = $xmlData.CreateElement("childPort")
$childSecure = $xmlData.CreateElement("childSecure")
$childProxyId = $xmlData.CreateElement("childProxyId ")
# Setting the childNode values
$childIP.set_InnerXML($dataObject.childIP)
$childPort.set_InnerXML($dataObject.childPort)
$childSecure.set_InnerXML($dataObject.childSecure)
$childProxyId.set_InnerXML($dataObject.childProxyId)
$childProxyInfo.AppendChild($childIP)
$childProxyInfo.AppendChild($childPort)
$childProxyInfo.AppendChild($childSecure)
$childProxyInfo.AppendChild($childProxyId)
$xmlData.SelectSingleNode("//parent/childInfo").AppendChild($childProxyInfo)
$xmlData.Save($xmlPath)
} else {
$xmlData.SelectNodes("//parent/childInfo") | ForEach-Object {
if (!($_.childProxyId -eq $dataObject.childProxyId)){
Write-Host "dakota already exist-" $_.childProxyId
break
} else {
Write-Host "created childInfo for ******************** "$dataObject.childIP
$childProxyInfo = $xmlData.CreateElement("dakotaProxyInfo")
$childIP = $xmlData.CreateElement("childIP")
$childPort = $xmlData.CreateElement("childPort")
$childSecure = $xmlData.CreateElement("childSecure")
$childProxyId = $xmlData.CreateElement("childProxyId")
$childIP.set_InnerXML($dataObject.childIP)
$childPort.set_InnerXML($dataObject.childPort)
$childSecure.set_InnerXML($dataObject.childSecure)
$childProxyId.set_InnerXML($dataObject.childProxyId)
$childProxyInfo.AppendChild($childIP)
$childProxyInfo.AppendChild($childPort)
$childProxyInfo.AppendChild($childSecure)
$childProxyInfo.AppendChild($childProxyId)
$xmlData.SelectSingleNode("//parent/childInfo").AppendChild($childProxyInfo)
$xmlData.Save($xmlPath)
}
}
}
创建一个新的childinfo节点。那部分工作正常。在$dataobject
部分中,我要检查现有节点在数据对象中是否具有相同的childProxyId。如果存在,则不应再次创建同一节点。当前,它再次使用相同的childProxyId复制该节点。我的代码有什么问题?