当前位置:网站首页>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 :

  1. Get all Row label
  2. 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

原网站

版权声明
本文为[VFP of Garfield]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200535523534.html