We help IT Professionals succeed at work.
Get Started

Curious how Expert Awards are earned? Find out on this week's podcast, featuring Experts Exchange CEO Randy Redberg.Listen Now

x
Troubleshooting Question

create an xml file with a Parent Child schema

Fordraiders
Fordraiders asked
on
40 Views
Last Modified: 2020-09-04
I have the following code creating an xml file for a table i have.
table layout:
table - name "SKU_SUBMISSION"
QuoteNumber
AccountNumber
Sku
all text fields



Dim strSQL As String
    Dim rst As DAO.Recordset
    
    strSQL = "SELECT QuoteNumber, AccountNumber, Sku FROM Sku_Submission"
    
    Set rst = CurrentDb.OpenRecordset(strSQL)
    
   ' strPath = CurrentProject.Path & "\CategoryList.xml"
    strPath = "C:\Users\xxxx\OneDriveinc\Desktop\Escalation\EE\SkuSubmission.xml"
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    Dim objFile As Object
    Set objFile = fso.CreateTextFile(strPath, True, True)
    
    objFile.Write "<?xml version='1.0'?>" & vbCrLf
    objFile.Write "<EsrpPriceRequest>" & vbCrLf
    
    Do Until rst.EOF
        
        objFile.Write "<QuoteNumber>" & rst.Fields("QuoteNumber") & "</QuoteNumber>" & vbCrLf
        objFile.Write "<AccountNumber>" & rst.Fields("AccountNumber") & "</AccountNumber>" & vbCrLf
        objFile.Write "<Item>" & rst.Fields("Sku") & "</Item>" & vbCrLf
      
        
        rst.MoveNext
    Loop
    
    objFile.Write "</EsrpPriceRequest>"
    
    rst.Close
    Set rst = Nothing
    
    MsgBox "Complete"
This Output like this:
<?xml version="1.0"?>

-<EsrpPriceRequest>

<QuoteNumber>0030017523</QuoteNumber>

<AccountNumber>0800000713</AccountNumber>

<Sku>3BA56</Sku>

<QuoteNumber>0030017523</QuoteNumber>

<AccountNumber>0800000713</AccountNumber>

<Sku>1A005</Sku>

<QuoteNumber>0030017523</QuoteNumber>

<AccountNumber>0800000713</AccountNumber>

<Sku>1AC47</Sku>

<QuoteNumber>0030017523</QuoteNumber>

<AccountNumber>0800000713</AccountNumber>

<Sku>6K305</Sku>

</EsrpPriceRequest>
with Items and Item  Parent Child


I need the xml to look like this:
<?xml version="1.0" encoding="UTF-8" standalone="true"?>

-<EsrpPriceRequest>

<QuoteNumber>0030017523</QuoteNumber>

<AccountNumber>0800000713</AccountNumber>


-<Items>

<Item>3BA56</Item>

<Item>1A005</Item>

<Item>1AC47</Item>

<Item>6K305</Item>

</Items>

</EsrpPriceRequest>


Thanks
fordraiders
Comment
Watch Question
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE