如何使用VBScript从XML文件中读取两个节点之间的特定内容

时间:2017-11-07 11:55:03

标签: xml vbscript

我的XML文件包含许多{ "customer_data": { "customer_type": "MERCHANT", "person_details": { "email_address": "mca.dipak-facilitator@gmail.com", "name": { "prefix": "Mrs.", "given_name":"Dipak", "surname": "Bhalodiya", "middle_name": "Prakash" }, "phone_contacts": [ { "phone_number_details": { "country_code": "91", "national_number": "8585868489" }, "phone_type": "HOME" } ], "home_address": { "line1": "11, outer ring road", "state": "Karnataka", "city": "Bangalore", "country_code": "US", "postal_code": "560103" }, "date_of_birth": { "event_type": "BIRTH", "event_date": "1987-12-29T23:59:59.999Z" }, "nationality_country_code": "US", "identity_documents": [ { "type": "SOCIAL_SECURITY_NUMBER", "value": "ABCDEF34646", "partial_value": false, "issuer_country_code": "US" } ] }, "business_details": { "phone_contacts": [ { "phone_number_details": { "country_code": "91", "national_number": "9740216087" }, "phone_type": "FAX" } ], "business_address": { "line1": "11, outer ring road", "state": "Karnataka", "city": "Bangalore", "country_code": "US", "postal_code": "560103" }, "business_type": "PROPRIETORSHIP", "category": "1004", "sub_category": "2025", "names": [ { "type": "LEGAL", "name": "DIPAK STORE" } ], "business_description": "Arts and handicrafts", "event_dates": [ { "event_type": "ESTABLISHED", "event_date": "2009-01-31T13:59:45Z" } ], "website_urls": [ "https://www.skyproductivity.com" ], "annual_sales_volume_range": { "minimum_amount": { "value": "2000", "currency": "USD" }, "maximum_amount": { "value": "3000", "currency": "USD" } }, "average_monthly_volume_range": { "minimum_amount": { "value": "2000", "currency": "USD" }, "maximum_amount": { "value": "3000", "currency": "USD" } }, "identity_documents": [ { "type": "TAX_IDENTIFICATION_NUMBER", "value": "ABCDEF34646", "partial_value": false, "issuer_country_code": "US" } ], "email_contacts": [ { "email_address": "customer-service@example.com", "role": "CUSTOMER_SERVICE" } ] }, "financial_instrument_data": { "bank_details": [ { "nick_name": "Bank of America", "account_number": "130385868974", "account_type": "CHECKING", "currency_code": "USD", "identifiers": [ { "type": "ROUTING_NUMBER_1", "value": "325272063" } ] } ] }, "preferred_language_code": "en_US", "primary_currency_code": "USD", "referral_user_payer_id": { "type": "PAYER_ID", "value": "2281707" }, "partner_specific_identifiers": [ { "type": "TRACKING_ID", "value": "130370723501" } ] }, "requested_capabilities": [ { "capability": "API_INTEGRATION", "api_integration_preference": { "partner_id": "2281707", //My own Partner Id "rest_api_integration": { "integration_method": "PAYPAL", "integration_type": "THIRD_PARTY" }, "rest_third_party_details": { "partner_client_id": "My Test Account Client ID", //My Client ID of Test Account "feature_list": [ "PAYMENT", "REFUND" ] } } } ], "web_experience_preference": { "partner_logo_url": "https://www.example.com/logo/", "return_url": "http://localhost/skyinvoice/htdocs/", "action_renewal_url": "http://localhost/skyinvoice/htdocs/" }, "collected_consents": [ { "type": "SHARE_DATA_CONSENT", "granted": true } ], "products": [ "EXPRESS_CHECKOUT" ] } 个节点,我想要读取位于<authentication...></authentication><authentication name="allow-list">个节点之间的文件内容。

有人可以告诉我怎么做吗?如何使用VBScript从</authentication>节点开始读取文件?

test.xml文件包含:

<authentication name=allow-list">

我尝试了以下代码。我能够获取选择器值但无法从<?xml ...?> <authentication name="deny-list"> <selector> </selector> </authentication> <authentication name="allow-list"> <selector> </selector> </authentication> 读取。

<authentication name="allow-list">

1 个答案:

答案 0 :(得分:0)

假设<authentication name="allow-list"></authentication总是在不同的行上,只需执行此类操作(如果该条件不适用,请告诉我,我会调整代码):

authStart = "<authentication"
authEnd = "</authentication>"
isInFileSection = False ' keeps track if the current line is between a start and end authentication tag

Do Until objFile.AtEndOfStream
    strLine = objFile.ReadLine
    If isInFileSection Then
        If InStr(strLine, authEnd) = 0 then
            filetxt.WriteLine strLine
        Else
            isInFileSection = False
        End If
    Else
        If InStr(strLine, authStart) > 0 Then
            isInFileSection = True
        End If
    End If
Loop
相关问题