当前位置:网站首页>The temporary table from XML to VFP is simple and easy to use and worth collecting
The temporary table from XML to VFP is simple and easy to use and worth collecting
2022-06-25 11:43:00 【VFP of Garfield】
Garfield's VFP| Blue sky textile of the fox Friends Association sent for help , Say I have one XML I don't know how to convert to a table .
Although the front has written XML It's just a string , Also taught to use Microsoft.XMLDOM Parsing , But this time the format is a little different , I didn't say , So cat cat took action , Today's article .
XML and JSON Two major data formats for heterogeneous systems , And quite a few fox friends don't know XML and JSON How to parse , Many previous articles have talked about JSON How to deal with , By contrast ,XML Less articles .
In today's mixed development time , Be sure to master the parsing of these two formats .
From blue sky textile XML Format .
<?xml version="1.0" encoding="GB2312"?>
<Data INFO="YIKAIFAPIAO">
<YKFP>
<Row Invoice number ="272531" Invoice date ="2021-12-22" Customer name =" Jiaxing Textile Co., Ltd " Total price and tax ="2954.5" Invoice code ="211130" Total amount ="2614.6" Tax amount ="339.9"/>
<Row Invoice number ="272530" Invoice date ="2021-12-18" Customer name =" Wujiang Textile Co., Ltd " Total price and tax ="100000" Invoice code ="211130" Total amount ="88495.57" Tax amount ="11504.43"/>
<Row Invoice number ="272529" Invoice date ="2021-12-10" Customer name =" Suzhou Textile Technology Co., Ltd " Total price and tax ="52000" Invoice code ="211130" Total amount ="46017.7" Tax amount ="5982.3"/>
<Row Invoice number ="272528" Invoice date ="2021-12-10" Customer name =" Suzhou Textile Technology Co., Ltd " Total price and tax ="100000" Invoice code ="211130" Total amount ="88495.58" Tax amount ="11504.42"/>
<Row Invoice number ="272527" Invoice date ="2021-12-10" Customer name =" Wujiang Silk Trade Co., Ltd " Total price and tax ="48000" Invoice code ="211130" Total amount ="42477.88" Tax amount ="5522.12"/>
<Row Invoice number ="272526" Invoice date ="2021-12-10" Customer name =" Suzhou Textile Co., Ltd " Total price and tax ="100000" Invoice code ="211130" Total amount ="88495.58" Tax amount ="11504.42"/>
<Row Invoice number ="272525" Invoice date ="2021-12-10" Customer name =" Wujiang Textile Co., Ltd " Total price and tax ="35123.2" Invoice code ="211130" Total amount ="31082.48" Tax amount ="4040.72"/>
<Row Invoice number ="272524" Invoice date ="2021-12-07" Customer name =" Wujiang Textile Co., Ltd " Total price and tax ="35123.2" Invoice code ="211130" Total amount ="31082.48" Tax amount ="4040.72"/>
</YKFP>
</Data>
XML Follow HTML Very similar , They are all tagging declarative languages , You can see that there are many in the label Rows label , What we usually don't see is , All its data is placed in Row In the properties of the tag .
The way is as follows :
- Get all Row label
- Get each line Row All properties in
Start parsing XML, The focus is on how attributes are handled
utilize getElementsByTagName Method to get all the Row label
Then you get all the attributes of each row of labels
Attributes also have attribute names and values
Invoice number =“272525”, The invoice number is the attribute name ,272525 For attribute value .
Here is a place to pay attention to :
oxmldoc.LoadXML Is load XML Content
oxmldoc.Load Is load XML file
The two are different , Don't use it wrong , If the load succeeds, it will return .T.
Traverse and output all invoice data
cXml=" above XML"
oxmldoc=Createobject("Microsoft.XMLDOM")
?oxmldoc.LoadXML(cXml) &&xml For documents load, For content loadxml
oRowtag=oxmldoc.getElementsByTagName("Row")
For i=0 To oRowtag.Length-1
?" Attribute length ",oRowtag.item(i).Attributes.length
FOR j=0 TO oRowtag.item(i).Attributes.length-1
?oRowtag.Item(i).Attributes.Item(j).nodeName && Property name
?oRowtag.Item(i).Attributes.Item(j).Text && Property value
ENDFOR
Endfor
The next step is to create a temporary table , Write the temporary table row by row to complete the parsing , I won't help you write the code here .
analysis XML Another data representation for tags
XML The data format is as follows , This time the data is not in the attribute , But in the label , So there is only one layer to parse , More easily .
<Fp>
<Djh></Djh>
<Fpzl> VAT special invoice </Fpzl>
<Lbdm>211130</Lbdm>
<Fphm>272525</Fphm>
<Kprq>20211210</Kprq>
<Gfmc> Wujiang Textile Co., Ltd </Gfmc>
</Fp>
TEXT TO lcXML NOSHOW TEXTMERGE
<Fp>
<Djh></Djh>
<Fpzl> VAT special invoice </Fpzl>
<Lbdm>211130</Lbdm>
<Fphm>272525</Fphm>
<Kprq>20211210</Kprq>
<Gfmc> Wujiang Textile Co., Ltd </Gfmc>
</Fp>
ENDTEXT
oxmldoc=Createobject("Microsoft.XMLDOM")
?oxmldoc.LoadXML(lcXML) &&xml For documents load, For content loadxml
oRowtag=oxmldoc.getElementsByTagName("Fp")
?oRowtag
For i=0 To oRowtag.Length-1
?oRowtag.Item(i).nodeName && Property name
?oRowtag.Item(i).Text && Property value
Endfor
It's all output from traversal , Continue to write the temporary table , You don't have to do it for me .
Then I also encapsulate a class library , It is specially used for single table conversion mode , In this case , Qiyou three-tier development framework is right XML and JSON The support of is relatively perfect .
Originality is not easy. , Let's move our fingers Collection 、 give the thumbs-up 、 Looking at !
More information http://www.sn58.cn
边栏推荐
- Countdownlatch source code analysis
- Subclass a inherits from parent class B, a a = new a(); Then the execution sequence of the constructor of parent class B, the static code block of parent class B, the non static code block of parent c
- C disk uses 100% cleaning method
- Whole process of web page request
- Solution to the timeout scenario of Flink streaming computing (official live broadcast)
- Shichuang energy rushes to the scientific innovation board: it plans to raise 1.1 billion yuan, with an annual revenue of 700million yuan and a 36% decrease in net profit
- Niuke.com: Candy distribution
- Convergence by probability
- 寿命分布 4种
- Ladder Side-Tuning:预训练模型的“过墙梯”
猜你喜欢
Thingpanel publie le client mobile IOT (Multi - images)
Vulnérabilité à l'injection SQL (contournement)
推荐一款M1电脑可用的虚拟机软件
Idea local launch Flink task
Research on parallel computing architecture of meteorological early warning based on supercomputing platform
Niuke.com: Candy distribution
Specific meanings of node and edge in Flink graph
Record the process of submitting code to openharmony once
Source code analysis of AQS & reentrantlock
CMU提出NLP新范式—重构预训练,高考英语交出134高分
随机推荐
Spark runs wordcount (case 1)
try-catch-finally
Course paper + code and executable EXE file of library information management system based on C language
How to use the markdown editor
依概率收敛
An interesting logic SRC mining
Comment TCP gère - t - il les exceptions lors de trois poignées de main et de quatre vagues?
GC
Specific meanings of node and edge in Flink graph
Recommend a virtual machine software available for M1 computer
Big Endian 和 Little Endian
Shichuang energy rushes to the scientific innovation board: it plans to raise 1.1 billion yuan, with an annual revenue of 700million yuan and a 36% decrease in net profit
Detailed explanation of spark specification
Big endian and little endian
云原生数据湖以存储、计算、数据管理等能力通过信通院评测认证
How TCP handles exceptions during three handshakes and four waves
Customize to prevent repeated submission of annotations (using redis)
Explain websocket protocol in detail
Two ways of redis persistence -- detailed explanation of RDB and AOF
4 life distributions