?
Solved

Working with an XML document in VB6

Posted on 2013-11-02
2
Medium Priority
?
349 Views
Last Modified: 2013-11-02
Experts, i need to get some information from an xml file. From the sample below i need to get the <Text> of all field types of "Text" where the name of the message is "Default".

I have used the code below to get the names of the messages in the file. but i dont know where to go from here.

    Dim xdoc As MSXML2.DOMDocument
    Set xdoc = New MSXML2.DOMDocument
    xdoc.validateOnParse = False
   
    Dim message As IXMLDOMElement
   
    If xdoc.Load("C:\test.xml") Then
       ' The document loaded successfully.
       ' Now do something intersting.
       'DisplayNode xdoc.childNodes, 0
        For Each message In xdoc.selectNodes("/Messages/Message/Name")
       
            Debug.Print message.Text
       
        Next
       
    End If

<Messages>
  <Message>
    <Language>English</Language>
    <Name>DEFAULT</Name>
    <Code>Undefined</Code>
    <FontSize>7</FontSize>
    <Delay>5000</Delay>
    <Bold>0</Bold>
    <Width>200</Width>
    <Gap>0</Gap>
    <Height>200</Height>
    <Pixel>16</Pixel>
    <Orientation>Upside Up</Orientation>
    <Alternate0>No</Alternate0>
    <Alternate1>No</Alternate1>
    <Alternate7>No</Alternate7>
    <RepeatPitch>0</RepeatPitch>
    <RepeatPrint>0</RepeatPrint>
    <AutoPrintPitch>0</AutoPrintPitch>
    <LanguageShifts>English</LanguageShifts>
    <ExpirationRolldown>Off</ExpirationRolldown>
    <ExpirationDate1>
      <Day>30</Day>
      <Week>0</Week>
      <Month>0</Month>
      <Year>0</Year>
    </ExpirationDate1>
    <ExpirationDate2>
      <Day>60</Day>
      <Week>0</Week>
      <Month>0</Month>
      <Year>0</Year>
    </ExpirationDate2>
    <TimeCreated>
      <Date>
        <Year>2013</Year>
        <Month>1</Month>
        <Day>24</Day>
      </Date>
      <Time>
        <Hour>11</Hour>
        <Minute>19</Minute>
      </Time>
    </TimeCreated>
    <CounterDate>
      <Date>
        <Year>2013</Year>
        <Month>1</Month>
        <Day>24</Day>
      </Date>
    </CounterDate>
    <Shift>
      <Text>A</Text>
      <Time>
        <Hour>8</Hour>
        <Minute>0</Minute>
      </Time>
    </Shift>
    <Counter1>
      <Start>0</Start>
      <Upper>100000</Upper>
      <Lower>0</Lower>
      <Increment>1</Increment>
      <Repeat>0</Repeat>
      <RepeatStart>0</RepeatStart>
      <Digits>6</Digits>
      <LeadZero>Yes</LeadZero>
      <Value>0</Value>
      <WrapAround>Yes</WrapAround>
    </Counter1>
    <Counter2>
      <Start>0</Start>
      <Upper>100000</Upper>
      <Lower>0</Lower>
      <Increment>1</Increment>
      <Repeat>0</Repeat>
      <RepeatStart>0</RepeatStart>
      <Digits>6</Digits>
      <LeadZero>Yes</LeadZero>
      <Value>0</Value>
      <WrapAround>Yes</WrapAround>
    </Counter2>
    <Field>
      <Type>Text</Type>
      <Language>English</Language>
      <Text>CITRONIX CIJ</Text>
      <FontSize>16</FontSize>
      <FontName>30021600</FontName>
      <Bold>0</Bold>
      <Gap>1</Gap>
      <X>0</X>
      <Y>0</Y>
      <Orientation>Upside Up</Orientation>
    </Field>
    <Field>
      <Type>Text</Type>
      <Language>English</Language>
      <Text>OCTOBER</Text>
      <FontSize>16</FontSize>
      <FontName>30021600</FontName>
      <Bold>0</Bold>
      <Gap>1</Gap>
      <X>0</X>
      <Y>0</Y>
      <Orientation>Upside Up</Orientation>
    </Field>
    <Field>
      <Type>AutoCode</Type>
      <Language>English</Language>
      <Format>MMDDYY</Format>
      <DateDelimiter>/</DateDelimiter>
      <FontSize>7</FontSize>
      <FontName>30020700</FontName>
      <Bold>0</Bold>
      <Gap>1</Gap>
      <X>160</X>
      <Y>0</Y>
      <Orientation>Upside Up</Orientation>
    </Field>
    <Field>
      <Type>AutoCode</Type>
      <Language>English</Language>
      <Format>HHMMSS</Format>
      <TimeDelimiter>:</TimeDelimiter>
      <FontSize>7</FontSize>
      <FontName>30020700</FontName>
      <Bold>0</Bold>
      <Gap>1</Gap>
      <X>160</X>
      <Y>9</Y>
      <Orientation>Upside Up</Orientation>
    </Field>
  </Message>
</Messages>
0
Comment
Question by:Basicfarmer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 total points
ID: 39619209
Two ways to add that (tested in VBA only but should be the same):
        For Each message In xdoc.selectNodes("/Messages/Message/Name")
            Debug.Print message.Text
            ' added below to get fields in a separate loop
            If message.Text = "DEFAULT" Then
                Dim FieldText As IXMLDOMElement
                For Each FieldText In message.parentNode.selectNodes("Field[Type='Text']/Text")
                    Debug.Print "* " & FieldText.Text
                Next
            End If
        Next
        ' OR, do it in one go
        Dim messageFieldText As IXMLDOMElement
        For Each messageFieldText In xdoc.selectNodes("/Messages/Message[Name='DEFAULT']/Field[Type='Text']/Text")
            Debug.Print "** " & messageFieldText.Text
        Next

Open in new window

0
 

Author Closing Comment

by:Basicfarmer
ID: 39619277
Perfect!!!

Thanks...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question