我想創建帶有文本的元素OutputPath。這就是我想要的:創建不帶命名空間的XML元素
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>Text</OutputPath>
</PropertyGroup>
,這就是我得到:
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath xmlns="">Text</OutputPath>
</PropertyGroup>
一切都很好,但是當我創建元素的東西不斷增加的xmlns =「」它。
然後我收到錯誤:錯誤MSB4097:元素下的元素可能沒有自定義的XML名稱空間。
// Load the Project (.innoproj or .nsisproj file)
xmlDoc := nil;
currentConfigurationNode := nil;
xmlDoc := CreateOleObject('Microsoft.XMLDOM') as IXMLDOMDocument2;
xmlDoc.async := False;
//xmlDoc.setProperty('SelectionNamespaces', 'xmlns="http://schemas.microsoft.com/developer/msbuild/2003"'); << this line does nothing
xmlDoc.load(projPath);
if xmlDoc.parseError.errorCode <> 0 then
begin
xmlDoc := nil;
currentConfigurationNode := nil;
raise Exception.Create('Cannot not load Project file! Details: ' + xmlDoc.parseError.reason);
end;
// Find appropriate element and get it's value
{ <?xml><Project><PropertyGroup Condition=" '$(Configuration)' == 'XXX' "> }
propertyGroup := xmlDoc.selectNodes('/Project/PropertyGroup');
for I := 0 to propertyGroup.length - 1 do
begin
node := propertyGroup[I];
if (node.attributes.length > 0) then
begin
Temp := String(node.attributes.getNamedItem('Condition').Text);
if(Temp.Contains('$(Configuration)') and Temp.Contains(projConfiguration)) then
begin
// Do all operations on this node
currentConfigurationNode := propertyGroup[I];
break;
end;
end;
end;
Result := True;
except
on Exception do
Result := False;
end;
創建(新)節點:
// This is correct Node for selected Configuration
node := currentConfigurationNode.selectSingleNode(PPED^.XmlTag);
if(node <> nil) then
if(PPED^.Value <> '') then
begin
elementNode := currentConfigurationNode.appendChild(xmlDoc.createElement(PPED^.XmlTag));
elementNode.text := PutSymbol(PPED^.Strip, PPED^.Value); << Something adds xmls="" to this element
end;
Slappy,你使用的是什麼delphi版本?最近的delphi版本包括OmniXML支持,並且不公開這種問題。 – whosrdaddy