我无法从以下xml文件中提取任何值。
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header/>
<env:Body env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<m:GetListOfAllLatestVariantsResponse xmlns:m="http://www.posti-care_suite.posti.nokia.com/POSTI_CareSuite_Interface.wsdl">
<result soapenc:arrayType="n1:Variant5[1]" xmlns:n1="http://posti.nokia.com/server/caresuite/webservice/types">
<variant xsi:type="n1:Variant5">
<variantID xsi:type="xsd:long">7115932272</variantID>
<name xsi:type="xsd:string">N8-00 RM-596 Country Variant United Kingdom GB Belle V6 Dark Gre</name>
<productCode xsi:type="xsd:string">059C5Q8</productCode>
<mandatoryFilesSize xsi:type="xsd:long">319898701</mandatoryFilesSize>
<optionalFilesSize xsi:type="xsd:long">1045013246</optionalFilesSize>
<files soapenc:arrayType="n1:File4[19]">
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">RM596_059C5Q8_111.040.1511_007.vpl</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">5316</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1211/0218/7115932073/6425438C_RM596_059C5Q8_111.040.1511_007.vpl</downloadURL>
<checksum xsi:type="xsd:string">1680163724</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">RM596_059C5Q8_111.040.1511_007.dcp</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">31743</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1211/0218/7115933784/18333A08_RM596_059C5Q8_111.040.1511_007.dcp</downloadURL>
<checksum xsi:type="xsd:string">406010376</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">RM-596_111.040.1511_79u_prd.core.fpsx</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">131593310</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1207/3115/7087503025/RM-596_111.040.1511_79u_prd.core.fpsx</downloadURL>
<checksum xsi:type="xsd:string">1419340992</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">RM-596_111.040.1511_01.01_Euro_1_79u_prd.rofs2.fpsx</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">59185951</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1207/3115/7087503335/RM-596_111.040.1511_01.01_Euro_1_79u_prd.rofs2.fpsx</downloadURL>
<checksum xsi:type="xsd:string">956264830</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">RM-596_111.040.1511_377.01_default_79u.2012.20_prd.rofs3.fpsx</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">46565</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1211/0218/7115932076/2C5CE665_RM-596_111.040.1511_377.01_default_79u.2012.20_prd.rofs3.fpsx</downloadURL>
<checksum xsi:type="xsd:string">744285797</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">RM-596_111.040.1511_377.01_default_79u.2012.20.uda.fpsx</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">124438076</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1211/0218/7115933788/4F8B5CF8_RM-596_111.040.1511_377.01_default_79u.2012.20.uda.fpsx</downloadURL>
<checksum xsi:type="xsd:string">1334533368</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">RM596_APE_ONLY_ENO_11w36_v0.162.fpsx</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">4593644</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1112/1506/6514839560/RM596_APE_ONLY_ENO_11w36_v0.162.fpsx</downloadURL>
<checksum xsi:type="xsd:string">285947104</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">RM-596_M001.56.emmc.fpsx</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">1044986030</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1208/2113/7087773772/8E08B787_RM-596_M001.56.emmc.fpsx</downloadURL>
<checksum xsi:type="xsd:string">2382935943</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">RM-596_data_block</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">4112</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/fdp/interface/FiRe/2010/6/--FID--A0A22XPGXOEFJ/--LID--FiRe1277360142761/RM-596_data_block</downloadURL>
<checksum xsi:type="xsd:string">166635140</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">ive3_otp_template_production.bin</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">40</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/fdp/interface/FiRe/2010/3/--FID--A0A22UMCDERPY/--LID--FiRe1269607336867/ive3_otp_template_production.bin</downloadURL>
<checksum xsi:type="xsd:string">3604450678</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">093490v1.pcx</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">8365</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/fdp/interface/FiRe/2010/8/--FID--A0A22UUKBNMGX/--LID--FiRe1281620803410/093490v1.pcx</downloadURL>
<checksum xsi:type="xsd:string">919543664</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">040-093490_P4067_006.xml</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">2610</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/fdp/interface/FiRe/2010/9/--FID--A0A22GGQDQJHV/--LID--FiRe1285052118474/24D0D5B4_040-093490_P4067_006.xml</downloadURL>
<checksum xsi:type="xsd:string">617665972</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">RM596_059C5Q8_size_ccc_v2.0.bin</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">472</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/fdp/interface/FiRe/2011/8/--FID--A0A22YXSWDMNO/--LID--FiRe1312914775006/E938259F_RM596_059C5Q8_size_ccc_v2.0.bin</downloadURL>
<checksum xsi:type="xsd:string">3912770975</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">RM596_059C5Q8_size_hwc_v2.0.bin</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">212</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/fdp/interface/FiRe/2011/8/--FID--A0A22GTHOJDFH/--LID--FiRe1312914776256/A65EB470_RM596_059C5Q8_size_hwc_v2.0.bin</downloadURL>
<checksum xsi:type="xsd:string">2791224432</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">simlock_3gstandard_bb5_crcA59A.bin</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">964</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1111/2911/6514812504/simlock_3gstandard_bb5_crcA59A.bin</downloadURL>
<checksum xsi:type="xsd:string">1270261311</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">RM-596_M001.56.emmc.cardverref.xml</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">386</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1208/2113/7087773773/CB9FED13_RM-596_M001.56.emmc.cardverref.xml</downloadURL>
<checksum xsi:type="xsd:string">3416255763</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">MC_F_nocard.mcard.cardverref.xml</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">131</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/fdp/interface/FiRe/2011/8/--FID--A0A22ALNMVCGG/--LID--FiRe1314695176834/39195667_MC_F_nocard.mcard.cardverref.xml</downloadURL>
<checksum xsi:type="xsd:string">957961831</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">RM596_059C5Q8_007.spr</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">9924</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1211/0218/7115933803/A4CB1ED5_RM596_059C5Q8_007.spr</downloadURL>
<checksum xsi:type="xsd:string">2764775125</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
<file xsi:type="n1:File4">
<fileName xsi:type="xsd:string">RM596_059C5Q8_111.040.1511_007_signature.bin</fileName>
<relativePath xsi:type="xsd:string">Products/rm-596</relativePath>
<fileSize xsi:type="xsd:long">4096</fileSize>
<downloadURL xsi:type="xsd:string">http://nds2.fds-fire.nokia.com/p/d/fds_fire/1211/0218/7115932081/590998C6_RM596_059C5Q8_111.040.1511_007_signature.bin</downloadURL>
<checksum xsi:type="xsd:string">1493801158</checksum>
<checksumType xsi:type="xsd:int">1</checksumType>
</file>
</files>
<variantVersion xsi:type="n1:VariantVersion">
<swVersion xsi:type="xsd:string">111.040.1511</swVersion>
<certificateID xsi:type="xsd:long">0</certificateID>
<versions soapenc:arrayType="n1:Version[0]"/>
</variantVersion>
</variant>
</result>
</m:GetListOfAllLatestVariantsResponse>
</env:Body>
</env:Envelope>
我想提取像variantID,productCode,name这样的值,它们是节点&#34; variant&#34;的子节点。
我所做的只是使用XML绑定向导来获取包装器单元并在表单中抛出XMLDocument组件。
我的代码到目前为止解析了&#39; productCode&#39;:
procedure TForm1.ParseXMl(const aXMLText: string);
var
EnvelopeType: IXMLEnvelopeType;
ProductCode: string;
begin
XMLDocument1.XML.Text := aXMLText;
EnvelopeType := GetEnvelope(XMLDocument1);
ProductCode := EnvelopeType.Body.GetListOfAllLatestVariantsResponse.Result.Variant.ProductCode.Text;
Memo2.Text := 'Product Code: ' + ProductCode;
end;
问题是,每次我得到所需节点值的空字符串值。
答案 0 :(得分:2)
由于Delphi的TXMLNodeList
中XML命名空间的实现很差,XML绑定向导生成的代码无法正常工作。由于根元素带有命名空间,因此代码假定您在所有子节点上具有相同的命名空间。这会产生副作用,即当命名空间发生变化时,XML代码无法找到正确的节点,因为m:GetListOfAllLatestVariantsResponse
就是这种情况。我无法理解为什么这样实现,因为你可以在子节点上有多个命名空间。
您可以按照以下步骤解决此问题:
1)将文件Xml.XmlDoc.pas和Xml.xmldom.pas从源目录复制到项目目录并将它们包含在项目中
2)修改本地Xml.XmlDoc.pas文件
更改功能function TXMLNodeList.FindNode(NodeName: DOMString): IXMLNode;
function TXMLNodeList.FindNode(NodeName: DOMString): IXMLNode;
begin
Result := FindNode(NodeName, DefaultNamespaceURI);
// --> add these lines below
// node not found with default namespace, fallback to blank namespace
if not Assigned(Result) then
Result := FindNode(NodeName, '');
end;
3)修改本地Xml.xmldom.pas文件
将函数NodeMatches
更改为:
function NodeMatches(const Node: IDOMNode; const TagName, NamespaceURI: DOMString): Boolean;
begin
Result := ((NamespaceURI = '') or (SameNamespace(Node, NamespaceURI)) or (Node.namespaceURI= '')) and
((Node.NodeName = TagName) or (Node.LocalName = TagName));
end;
4)修改XML绑定向导生成的单元
我们必须反映GetListOfAllLatestVariantsResponse
节点使用另一个命名空间的事实:
procedure TXMLBodyType.AfterConstruction;
begin
RegisterChildNode('GetListOfAllLatestVariantsResponse', TXMLGetListOfAllLatestVariantsResponseType, 'http://www.posti-care_suite.posti.nokia.com/POSTI_CareSuite_Interface.wsdl');
inherited;
end;
答案 1 :(得分:1)
我做了一个快速测试,XML被加载但是访问者永远不会在所有者文档中找到他们的方式。我对这个问题没有答案。也许您需要获取原始模式文件。
或者,您可以尝试使用XPath访问节点:
procedure TForm1.btn1Click(Sender: TObject);
var
xmlDoc: IXMLDOMDocument;
node: IXMLDomNode;
begin
xmlDoc := CreateOleObject('Microsoft.XMLDOM') as IXMLDOMDocument;
xmlDoc.async := False;
xmlDoc.load('file.xml');
if xmlDoc.parseError.errorCode <> 0 then
raise Exception.Create('XML Load error:' + xmlDoc.parseError.reason);
node := xmlDoc.selectSingleNode('//variant/productCode');
if node <> nil then
ShowMessage(node.text)
else
ShowMessage('Node not found');
end;