Hi Forum,
I have been trying to create an automated report in word, using VB.NET.
I am trying to build a program, which will read an XML template of the word document, which should traverse through the XML document, and create the desired elements from the name of the XML tags.
My xml file looks like the following
So say if my code hits the heading1 tag, it will create an heading 1 in word, and it should then look for the title attribute which goes with the heading and fill in the text into the word document.
I am having problems reading the XML document into VB.NET. I don't know the cleanest way to traverse the document from top to bottom, but also get the code to return a list of all the child nodes from specific tags.
Eg if i hit the FeatTable tag, I want it to create a table in the word document and then return all the tables rows, so that they can be printed into the document.
I want my code to be somthing like:
I am happy with the word side of things its just the traversing of the XML document thats causing me great headaches.
Any help would be greatly appreciated!
Boyindie
I have been trying to create an automated report in word, using VB.NET.
I am trying to build a program, which will read an XML template of the word document, which should traverse through the XML document, and create the desired elements from the name of the XML tags.
My xml file looks like the following
Code:
<Document> <Heading1> <Title> 1.0 Introduction</Title> <Heading2> <Title> 1.1 Test Laboratory</Title> <FeatTable> <row id="1"> <Row1>Telephone</Row1> <FeatId>7</FeatId> <FeatItem>1</FeatItem> </row> <row id="1"> <FeatTiltle>Fax</FeatTiltle> <FeatId>7</FeatId> <FeatItem>2</FeatItem> </row> <row id="2"> <FeatTiltle>Email</FeatTiltle> <FeatId>7</FeatId> <FeatItem>3</FeatItem> </row> <row id="3"> <FeatTiltle>Website</FeatTiltle> <FeatId>7</FeatId> <FeatItem>4</FeatItem> </row> </FeatTable> </Heading2> <Heading2> <Title> 1.2 Test Location</Title> <FeatTable> <row id="1"> <Row1>Telephone</Row1> <FeatId>7</FeatId> <FeatItem>1</FeatItem> </row> <row id="2"> <FeatTiltle>Website</FeatTiltle> <FeatId>7</FeatId> <FeatItem>4</FeatItem> </row> </FeatTable> </Heading2> </Heading1> </Document>
I am having problems reading the XML document into VB.NET. I don't know the cleanest way to traverse the document from top to bottom, but also get the code to return a list of all the child nodes from specific tags.
Eg if i hit the FeatTable tag, I want it to create a table in the word document and then return all the tables rows, so that they can be printed into the document.
I want my code to be somthing like:
Code:
Public Sub main(ByVal xmlFile As String)
Dim reader As XmlTextReader = New XmlTextReader(xmlFile)
Dim val As String
Do While reader.Read
Select Case reader.NodeType
Case XmlNodeType.Element
Select Case reader.Name
Case "Document"
'CREATE NEW WORD DOCUMENT
Case "Heading1"
'Create top most heading
'Write heading title from title tag
Case "Heading2"
'Create sub heading
'Write heading title from title tag
Case "FeatTable"
'CREATE TABLE
'Get Table rows from file
End Select
End Select
Loop
WordDoc.PrintOut()
End Sub
Any help would be greatly appreciated!
Boyindie
Comment