This is a change up of yesterdays post to retrieve a Bible Chapter instead of a Verse. After selecting the Book from a Web Services populated CombBox and collecting the Chapter in a TextBox, a SOAP call to GetBibleWordsByBookTitleAndChapter is made and the returned XML parsed. This time the array of the XML document contains multiple data elements instead of a single Verse and so I need to loop through the array and retrieve the individual Verses. I prepend the Verse number and append a new line (`n) for separation of each verse during the loop.

Function ChapterLookup {
    $book = $bookComboBox.Text
    $chapter = $chapterTextBox.Text
    $bibleChapter = New-WebServiceProxy -uri "http://www.webservicex.net/BibleWebservice.asmx?WSDL"
    $theChapter = [xml]$bibleChapter.GetBibleWordsByBookTitleAndChapter($book,$chapter)
    $selections  = $theChapter.NewDataSet.Table | Select Verse, BibleWords
    $chapterOutputBox.Text = ""
    Foreach ($selection in $selections) {
        $chapterOutputBox.Text = $chapterOutputBox.Text + $selection.Verse + ") " + $selection.BibleWords + "`n"
    }
}

As mentioned before there is a delay when opening the script and after doing the lookup as external Web Services are requested. If you get a timeout, just wait a minute and try it again.

Here is an example of the returned XML –

<NewDataSet>
    <Table>
        <Book>1</Book>
        <BookTitle>Genesis</BookTitle>
        <Chapter>1</Chapter>
        <Verse>1</Verse>
        <BibleWords>In the beginning God created the heaven and the earth.</BibleWords>
    </Table>
    <Table>
        <Book>1</Book>
        <BookTitle>Genesis</BookTitle>
        <Chapter>1</Chapter>
        <Verse>2</Verse>
        <BibleWords>And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.</BibleWords>
    </Table>
</NewDataSet>

BibleChapterLookup

BibleChapterLookup.ps1

Advertisements