gpt4 book ai didi

xml - 无法使用 Delphi 中的 XML 绑定(bind)解析 XML 文本中的值

转载 作者:行者123 更新时间:2023-12-02 08:29:51 25 4
gpt4 key购买 nike

我无法从以下 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这样的值,它们是节点“variant”的子节点。

我所做的只是使用 XML 绑定(bind)向导来获取包装器单元并将 XMLDocument 组件放入表单中。

到目前为止我的代码解析“productCode”:

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;

问题是,每次我得到所需节点值的空字符串值。

最佳答案

由于 Delphi 的 TXMLNodeList 中 XML 命名空间的实现很差,XML 绑定(bind)向导生成的代码无法正常工作。由于根元素带有命名空间,因此代码假定所有子节点上都具有相同的命名空间。这有一个副作用,即当命名空间更改时,XML 代码无法找到正确的节点,就像 m:GetListOfAllLatestVariantsResponse 的情况一样。我无法理解为什么要这样实现,因为您可以在子节点上拥有多个 namespace 。

您可以按照以下步骤修复此问题:

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绑定(bind)向导生成的单元

我们必须反射(reflect) GetListOfAllLatestVariantsResponse 节点使用另一个命名空间的事实:

procedure TXMLBodyType.AfterConstruction;
begin
RegisterChildNode('GetListOfAllLatestVariantsResponse', TXMLGetListOfAllLatestVariantsResponseType, 'http://www.posti-care_suite.posti.nokia.com/POSTI_CareSuite_Interface.wsdl');
inherited;
end;

关于xml - 无法使用 Delphi 中的 XML 绑定(bind)解析 XML 文本中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30244875/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com