可以考滤用Delphi带的XML Data Binding绑定,然后读取数据就方便了。参考:http://hi.baidu.com/0xcea4/blog/item/efda40ae580433f2fbed508a.html
直接解析XML,使用NativeXML解析起来容易很
TO:楼主 兄弟我最近也有相同的困难,正在用XML Data Binding在试,但感觉很烦。 请你找到合适的方法后一定告诉我一下哦。谢谢了。另请有类似经验的朋友帮忙哦。
可以用delphi的xmldocument组件来进行xml读取分析,然后将其存入数据库中。
这些都试过,但要存入数据库,得事先知道有哪些元素啊,我在想有没有一种方法可以实现,把整个XML当作一个数据库来操作,也试了 XML PAper 但最终还是出错,无法实现,我不知道错 在 哪?当我点击右键后,弹出菜单 ,按下 Create Datapacket from XML 后,:this name may not contain the '@' character -->@<--XH.大家快帮忙啊!快要累死人啦,怎么会出现XML这种累死人的数据格式呢?!!!!
写个伪代码: xml: TNativeXml; begin xml := TNativexml.Create; xml.loadfromFile(xml文件); for i := 0 to xml.root.NodeCount - 1 do begin CNode := xml.root.Nodes[i]; //这里可以如上for j := 0 to CNode.NodeCount - 1 do //可以写个递归,一直到最终子节点 CNode.ReadStringAttribut//具体忘记是啥玩意了,参考对应的方法函数 end; end;
兄弟我最近也有相同的困难,正在用XML Data Binding在试,但感觉很烦。
请你找到合适的方法后一定告诉我一下哦。谢谢了。另请有类似经验的朋友帮忙哦。
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="GCZJWJ" type="GCZJWJType"/>
<xs:complexType name="GCZJWJType">
<xs:sequence>
<xs:element name="GCMS" type="GCMSType"/>
<xs:element name="GCXMZJ" type="GCXMZJType"/>
<xs:element name="DXGC" type="DXGCType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="WJMC" type="xs:string"/>
<xs:attribute name="Ver" type="xs:string"/>
<xs:attribute name="BZLB" type="xs:string"/>
</xs:complexType>
<xs:element name="GCMS" type="GCMSType"/>
<xs:complexType name="GCMSType">
<xs:sequence>
<xs:element name="JSDW" type="JSDWType"/>
<xs:element name="SGDW" type="SGDWType"/>
<xs:element name="TBXZ" type="TBXZType"/>
<xs:element name="ZSM" type="ZSMType"/>
</xs:sequence>
<xs:attribute name="GCMC" type="xs:string"/>
<xs:attribute name="JJLX" type="xs:string"/>
<xs:attribute name="ZYLB" type="xs:string"/>
<xs:attribute name="GCZJ" type="xs:string"/>
<xs:attribute name="JZMJ" type="xs:string"/>
<xs:attribute name="BZDW" type="xs:string"/>
<xs:attribute name="BZR" type="xs:string"/>
<xs:attribute name="BZRQ" type="xs:string"/>
</xs:complexType>
<xs:element name="JSDW" type="JSDWType"/>
<xs:complexType name="JSDWType">
<xs:sequence/>
<xs:attribute name="ZBR" type="xs:string"/>
<xs:attribute name="FRDB" type="xs:string"/>
<xs:attribute name="ZJDW" type="xs:string"/>
<xs:attribute name="ZJFRDB" type="xs:string"/>
<xs:attribute name="ZJGCS" type="xs:string"/>
<xs:attribute name="ZCZH" type="xs:string"/>
</xs:complexType>
<xs:element name="SGDW" type="SGDWType"/>
<xs:complexType name="SGDWType">
<xs:sequence/>
<xs:attribute name="TBR" type="xs:string"/>
<xs:attribute name="FRDB" type="xs:string"/>
<xs:attribute name="ZJGCS" type="xs:string"/>
<xs:attribute name="ZCZH" type="xs:string"/>
</xs:complexType>
<xs:element name="TBXZ" type="TBXZType"/>
<xs:simpleType name="TBXZType">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:element name="ZSM" type="ZSMType"/>
<xs:complexType name="ZSMType">
<xs:sequence>
<xs:element name="NR" type="NRType"/>
<xs:element name="JGXX" type="JGXXType"/>
<xs:element name="JJGD" type="JJGDType"/>
<xs:element name="GCTZ" type="GCTZType"/>
</xs:sequence>
</xs:complexType>
<xs:element name="NR" type="NRType"/>
<xs:simpleType name="NRType">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:element name="JGXX" type="JGXXType"/>
<xs:simpleType name="JGXXType">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:element name="JJGD" type="JJGDType"/>
<xs:simpleType name="JJGDType">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:element name="GCTZ" type="GCTZType"/>
<xs:simpleType name="GCTZType">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:element name="GCXMZJ" type="GCXMZJType"/>
<xs:complexType name="GCXMZJType">
<xs:sequence>
<xs:element name="FYXM" type="FYXMType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="FYXM" type="FYXMType"/>
<xs:complexType name="FYXMType">
<xs:sequence/>
<xs:attribute name="XH" type="xs:string"/>
<xs:attribute name="XMMC" type="xs:string"/>
<xs:attribute name="FL" type="xs:string"/>
<xs:attribute name="JE" type="xs:string"/>
<xs:attribute name="JSBF" type="xs:string"/>
</xs:complexType>
<xs:element name="DXGC" type="DXGCType"/>
<xs:complexType name="DXGCType">
<xs:sequence>
<xs:element name="DXGCF" type="DXGCFType"/>
<xs:element name="DWGC" type="DWGCType"/>
<xs:element name="SBF" type="SBFType"/>
</xs:sequence>
<xs:attribute name="XH" type="xs:string"/>
<xs:attribute name="DXGCMC" type="xs:string"/>
<xs:attribute name="GCZJ" type="xs:string"/>
</xs:complexType>
<xs:element name="DXGCF" type="DXGCFType"/>
<xs:complexType name="DXGCFType">
<xs:sequence>
<xs:element name="FYXM" type="FYXMType"/>
</xs:sequence>
</xs:complexType>
<xs:element name="FYXM" type="FYXMType"/>
<xs:complexType name="FYXMType">
<xs:sequence/>
<xs:attribute name="XH" type="xs:string"/>
<xs:attribute name="XMMC" type="xs:string"/>
<xs:attribute name="FL" type="xs:string"/>
<xs:attribute name="JE" type="xs:string"/>
<xs:attribute name="JSBF" type="xs:string"/>
</xs:complexType>
<xs:element name="DWGC" type="DWGCType"/>
<xs:complexType name="DWGCType">
<xs:sequence>
<xs:element name="DWGCF" type="DWGCFType"/>
<xs:element name="FBFX" type="FBFXType"/>
<xs:element name="CSXM" type="CSXMType"/>
<xs:element name="QTXM" type="QTXMType"/>
<xs:element name="YSJG" type="YSJGType"/>
</xs:sequence>
<xs:attribute name="XH" type="xs:string"/>
<xs:attribute name="DWGCMC" type="xs:string"/>
<xs:attribute name="GCZJ" type="xs:string"/>
<xs:attribute name="ZYLB" type="xs:string"/>
<xs:attribute name="JGXXSY" type="xs:string"/>
<xs:attribute name="TZSY" type="xs:string"/>
</xs:complexType>
<xs:element name="DWGCF" type="DWGCFType"/>
<xs:complexType name="DWGCFType">
<xs:sequence>
<xs:element name="FYXM" type="FYXMType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="FYXM" type="FYXMType"/>
<xs:complexType name="FYXMType">
<xs:sequence>
<xs:element name="FYXMZC" type="FYXMZCType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="XH" type="xs:string"/>
<xs:attribute name="XMMC" type="xs:string"/>
<xs:attribute name="FL" type="xs:string"/>
<xs:attribute name="JE" type="xs:string"/>
<xs:attribute name="JSBF" type="xs:string"/>
</xs:complexType>
<xs:element name="FYXMZC" type="FYXMZCType"/>
<xs:complexType name="FYXMZCType">
<xs:sequence/>
<xs:attribute name="XH" type="xs:string"/>
<xs:attribute name="XMMC" type="xs:string"/>
<xs:attribute name="FL" type="xs:string"/>
<xs:attribute name="JE" type="xs:string"/>
<xs:attribute name="JSBF" type="xs:string"/>
</xs:complexType>
<xs:element name="FBFX" type="FBFXType"/>
<xs:complexType name="FBFXType">
<xs:sequence>
<xs:element name="FXGC" type="FXGCType"/>
</xs:sequence>
</xs:complexType>
其实,不同的平台、工具实际衔接起来,问题多多首先是语言,其次是具体定义还有很多细节可能不完全一样,因为它的语法、协议还是有点复杂的——当然,我是一个“ini取代xml”的倡议者,上述观点有一定偏向性,注意识别
<xs:complexType name="FXGCType">
<xs:sequence>
<xs:element name="QFTJ" type="QFTJType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="QFBZ" type="QFBZType"/>
<xs:element name="QDXM" type="QDXMType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="FXGCMC" type="xs:string"/>
<xs:attribute name="GCZJ" type="xs:string"/>
</xs:complexType>
<xs:element name="QFTJ" type="QFTJType"/>
<xs:complexType name="QFTJType">
<xs:sequence>
<xs:element name="QFTJXM" type="QFTJXMType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="QFBZ" type="QFBZType"/>
<xs:simpleType name="QFBZType">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:element name="QDXM" type="QDXMType"/>
<xs:complexType name="QDXMType">
<xs:sequence>
<xs:element name="DEXM" type="DEXMType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="XMBM" type="xs:string"/>
<xs:attribute name="XMMC" type="xs:string"/>
<xs:attribute name="JLDW" type="xs:string"/>
<xs:attribute name="GCSL" type="xs:string"/>
<xs:attribute name="ZHDJ" type="xs:string"/>
<xs:attribute name="HJ" type="xs:string"/>
<xs:attribute name="GCNR" type="xs:string"/>
<xs:attribute name="XMTZ" type="xs:string"/>
<xs:attribute name="JSGZ" type="xs:string"/>
<xs:attribute name="RGF" type="xs:string"/>
<xs:attribute name="CLF" type="xs:string"/>
<xs:attribute name="JXF" type="xs:string"/>
<xs:attribute name="QGF" type="xs:string"/>
<xs:attribute name="LR" type="xs:string"/>
<xs:attribute name="ZJFS" type="xs:string"/>
</xs:complexType>
<xs:element name="DEXM" type="DEXMType"/>
<xs:complexType name="DEXMType">
<xs:sequence>
<xs:element name="ZHDJZC" type="ZHDJZCType"/>
<xs:element name="DEXHL" type="DEXHLType"/>
</xs:sequence>
<xs:attribute name="DEBH" type="xs:string"/>
<xs:attribute name="XMMC" type="xs:string"/>
<xs:attribute name="JLDW" type="xs:string"/>
<xs:attribute name="GCSL" type="xs:string"/>
<xs:attribute name="ZHDJ" type="xs:string"/>
<xs:attribute name="HJ" type="xs:string"/>
<xs:attribute name="QFLB" type="xs:string"/>
<xs:attribute name="JSGD" type="xs:string"/>
<xs:attribute name="HSJL" type="xs:string"/>
<xs:attribute name="RGF" type="xs:string"/>
<xs:attribute name="CLF" type="xs:string"/>
<xs:attribute name="JXF" type="xs:string"/>
<xs:attribute name="QGF" type="xs:string"/>
<xs:attribute name="LR" type="xs:string"/>
<xs:attribute name="FXF" type="xs:string"/>
</xs:complexType>
<xs:element name="ZHDJZC" type="ZHDJZCType"/>
<xs:complexType name="ZHDJZCType">
<xs:sequence>
<xs:element name="FYXM" type="FYXMType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="BZ" type="xs:string"/>
</xs:complexType>
<xs:element name="FYXM" type="FYXMType"/>
<xs:complexType name="FYXMType">
<xs:sequence/>
<xs:attribute name="XH" type="xs:string"/>
<xs:attribute name="XMMC" type="xs:string"/>
<xs:attribute name="FL" type="xs:string"/>
<xs:attribute name="JE" type="xs:string"/>
<xs:attribute name="JSBF" type="xs:string"/>
</xs:complexType>
<xs:element name="DEXHL" type="DEXHLType"/>
<xs:complexType name="DEXHLType">
<xs:sequence>
<xs:element name="XHL" type="XHLType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="XHL" type="XHLType"/>
<xs:complexType name="XHLType">
<xs:sequence>
<xs:element name="PHB" type="PHBType"/>
</xs:sequence>
<xs:attribute name="BH" type="xs:string"/>
<xs:attribute name="YBH" type="xs:string"/>
<xs:attribute name="MC" type="xs:string"/>
<xs:attribute name="GG" type="xs:string"/>
<xs:attribute name="DW" type="xs:string"/>
<xs:attribute name="SL" type="xs:string"/>
<xs:attribute name="DJ" type="xs:string"/>
<xs:attribute name="LB" type="xs:string"/>
<xs:attribute name="GYFS" type="xs:string"/>
<xs:attribute name="ZYCL" type="xs:string"/>
</xs:complexType>
<xs:element name="PHB" type="PHBType"/>
<xs:complexType name="PHBType">
<xs:sequence>
<xs:element name="PHBZC" type="PHBZCType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="PHBZC" type="PHBZCType"/>
<xs:complexType name="PHBZCType">
<xs:sequence/>
<xs:attribute name="BH" type="xs:string"/>
<xs:attribute name="YBH" type="xs:string"/>
<xs:attribute name="MC" type="xs:string"/>
<xs:attribute name="GG" type="xs:string"/>
<xs:attribute name="DW" type="xs:string"/>
<xs:attribute name="SL" type="xs:string"/>
<xs:attribute name="DJ" type="xs:string"/>
<xs:attribute name="LB" type="xs:string"/>
<xs:attribute name="GYFS" type="xs:string"/>
</xs:complexType>
<xs:element name="QFTJXM" type="QFTJXMType"/>
<xs:complexType name="QFTJXMType">
<xs:sequence/>
<xs:attribute name="MC" type="xs:string"/>
<xs:attribute name="NR" type="xs:string"/>
</xs:complexType>
<xs:element name="CSXM" type="CSXMType"/>
<xs:complexType name="CSXMType">
<xs:sequence>
<xs:element name="CSFXGC" type="CSFXGCType"/>
</xs:sequence>
</xs:complexType>
<xs:element name="CSFXGC" type="CSFXGCType"/>
<xs:complexType name="CSFXGCType">
<xs:sequence>
<xs:element name="DECS" type="DECSType"/>
<xs:element name="FLCS" type="FLCSType"/>
<xs:element name="QFTJ" type="QFTJType"/>
<xs:element name="QFBZ" type="QFBZType"/>
</xs:sequence>
<xs:attribute name="FXGCMC" type="xs:string"/>
<xs:attribute name="GCZJ" type="xs:string"/>
</xs:complexType>
<xs:element name="DECS" type="DECSType"/>
<xs:complexType name="DECSType">
<xs:sequence>
<xs:element name="QDXM" type="QDXMType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="QDXM" type="QDXMType"/>
<xs:complexType name="QDXMType">
<xs:sequence>
<xs:element name="DEXM" type="DEXMType"/>
</xs:sequence>
<xs:attribute name="XMBM" type="xs:string"/>
<xs:attribute name="XMMC" type="xs:string"/>
<xs:attribute name="JLDW" type="xs:string"/>
<xs:attribute name="GCSL" type="xs:string"/>
<xs:attribute name="ZHDJ" type="xs:string"/>
<xs:attribute name="HJ" type="xs:string"/>
<xs:attribute name="GCNR" type="xs:string"/>
<xs:attribute name="XMTZ" type="xs:string"/>
<xs:attribute name="JSGZ" type="xs:string"/>
<xs:attribute name="RGF" type="xs:string"/>
<xs:attribute name="CLF" type="xs:string"/>
<xs:attribute name="JXF" type="xs:string"/>
<xs:attribute name="QGF" type="xs:string"/>
<xs:attribute name="LR" type="xs:string"/>
<xs:attribute name="ZJFS" type="xs:string"/>
</xs:complexType>
<xs:element name="FLCS" type="FLCSType"/>
<xs:complexType name="FLCSType">
<xs:sequence>
<xs:element name="FLCSJL" type="FLCSJLType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="FLCSJL" type="FLCSJLType"/>
<xs:complexType name="FLCSJLType">
<xs:sequence/>
<xs:attribute name="XMMC" type="xs:string"/>
<xs:attribute name="JSS" type="xs:string"/>
<xs:attribute name="JS" type="xs:string"/>
<xs:attribute name="FL" type="xs:string"/>
<xs:attribute name="JE" type="xs:string"/>
</xs:complexType>
<xs:element name="QFTJ" type="QFTJType"/>
<xs:simpleType name="QFTJType">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:element name="QFBZ" type="QFBZType"/>
<xs:simpleType name="QFBZType">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:element name="QTXM" type="QTXMType"/>
<xs:complexType name="QTXMType">
<xs:sequence>
<xs:element name="ZBRBF" type="ZBRBFType"/>
<xs:element name="TBRBF" type="TBRBFType"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ZBRBF" type="ZBRBFType"/>
<xs:complexType name="ZBRBFType">
<xs:sequence>
<xs:element name="ZBRXM" type="ZBRXMType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ZBRXM" type="ZBRXMType"/>
<xs:complexType name="ZBRXMType">
<xs:sequence/>
<xs:attribute name="XH" type="xs:string"/>
<xs:attribute name="XMMC" type="xs:string"/>
<xs:attribute name="JE" type="xs:string"/>
</xs:complexType>
<xs:element name="TBRBF" type="TBRBFType"/>
<xs:simpleType name="TBRBFType">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:element name="YSJG" type="YSJGType"/>
<xs:complexType name="YSJGType">
<xs:sequence>
<xs:element name="SB" type="SBType"/>
<xs:element name="RG" type="RGType"/>
<xs:element name="CL" type="CLType"/>
<xs:element name="JX" type="JXType"/>
</xs:sequence>
</xs:complexType>
<xs:element name="SB" type="SBType"/>
<xs:simpleType name="SBType">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:element name="RG" type="RGType"/>
<xs:complexType name="RGType">
<xs:sequence>
<xs:element name="RGXM" type="RGXMType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="RGXM" type="RGXMType"/>
<xs:complexType name="RGXMType">
<xs:sequence/>
<xs:attribute name="BH" type="xs:string"/>
<xs:attribute name="MC" type="xs:string"/>
<xs:attribute name="GG" type="xs:string"/>
<xs:attribute name="DW" type="xs:string"/>
<xs:attribute name="SL" type="xs:string"/>
<xs:attribute name="DJ" type="xs:string"/>
</xs:complexType>
<xs:element name="CL" type="CLType"/>
<xs:complexType name="CLType">
<xs:sequence>
<xs:element name="CLXM" type="CLXMType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="CLXM" type="CLXMType"/>
<xs:complexType name="CLXMType">
<xs:sequence/>
<xs:attribute name="BH" type="xs:string"/>
<xs:attribute name="MC" type="xs:string"/>
<xs:attribute name="GG" type="xs:string"/>
<xs:attribute name="DW" type="xs:string"/>
<xs:attribute name="SL" type="xs:string"/>
<xs:attribute name="DJ" type="xs:string"/>
</xs:complexType>
<xs:element name="JX" type="JXType"/>
<xs:complexType name="JXType">
<xs:sequence>
<xs:element name="JXXM" type="JXXMType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="JXXM" type="JXXMType"/>
<xs:complexType name="JXXMType">
<xs:sequence/>
<xs:attribute name="BH" type="xs:string"/>
<xs:attribute name="MC" type="xs:string"/>
<xs:attribute name="GG" type="xs:string"/>
<xs:attribute name="DW" type="xs:string"/>
<xs:attribute name="SL" type="xs:string"/>
<xs:attribute name="DJ" type="xs:string"/>
</xs:complexType>
<xs:element name="SBF" type="SBFType"/>
<xs:simpleType name="SBFType">
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:schema>
xml: TNativeXml;
begin
xml := TNativexml.Create;
xml.loadfromFile(xml文件);
for i := 0 to xml.root.NodeCount - 1 do
begin
CNode := xml.root.Nodes[i];
//这里可以如上for j := 0 to CNode.NodeCount - 1 do
//可以写个递归,一直到最终子节点
CNode.ReadStringAttribut//具体忘记是啥玩意了,参考对应的方法函数
end;
end;
FXMLDoc: TXMLDocument;
FXMLDoc := TXMLDocument.Create(Application);
FXMLDoc.LoadFromFile(AFileName);
vRootNode := FXMLDoc.DocumentElement;
vNode.NodeName
vNode.NodeValue
vnode.ChildNodes.Get(0).NodeValue
vNode.ChildNodes.First;
vNode.NextSibling;
vNode.Attributes['user']
FXMLDoc.free;
自己研究去吧