Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
michaelh1
Contributor II
Contributor II

tXMLMap loop inside loop

Hello,

 

I am working on job that will parse my xml and save it to multiple DB tables using tXMLMap and tDBOutput. My problem is that in tXMLMap i cant set loop element inside loop element example:

 

 

<author>
   <book>
    <chapter/>
    <chapter/>
   </book>
   <book>
    <chapter/>
    <chapter/>
   </book>
</author>

(as you can see i have loop of books that contains loop of chapters)

What is the best practice to parse such an xml?

 

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable

If you give the loop in the chapter then all the attributes will come.0683p000009MZvJ.png

And the output you will get

0683p000009MZrs.png

 

Don't forget to give kudos/accept the solution when a replay is helpful.

 

View solution in original post

5 Replies
Anonymous
Not applicable

Hi,

 

You can set loop in tXMLmap in a column if your datatype is document.

First, define  any column in txmlInput and give xpathquery as "." also check the getNodes button

0683p000009MZsF.pngIn the tXMLinput define the datatype of the new column as a document. Then right-click on the column and import structure from the XML file. Then set the loop in the column you want.

0683p000009MZsK.png

 

Don't forget to give kudos/accept the solution when a replay is helpful.

Thanks,

Aarif

michaelh1
Contributor II
Contributor II
Author

Hello,

 

i know how to use single loop in xml document. But what i need is to iterate all the chapters (loop of chapters) in each book. So basically what i need is to iterate loop of chapters in the loop of books.

Anonymous
Not applicable

Hi,

 

Basically you want to loop in the chapters. For that, you need to insert data inside all the chapter tag and then loop in the chapter. You will be able to loop into it.

michaelh1
Contributor II
Contributor II
Author

Yes you are right i need to loop all the chapters and store it to DB, but i also need to get the parent elements of element chapter author and book. lets say that my xml looks like this:

    <author>    
        <name>Author1</name>
		<books>
			<book>
				<name>Book1</name>
				<chapters>
					<chapter>
						<name>Chapter1</name>
					</chapter>
					<chapter>
						<name>Chapter2</name>
					</chapter>
				</chapters>
			</book>
			<book>
				<name>Book2</name>
				<chapters>
					<chapter>
						<name>Chapter1</name>
					</chapter>
					<chapter>
						<name>Chapter2</name>
					</chapter>
					<chapter>
						<name>Chapter3</name>
					</chapter>
				</chapters>
			</book>
		</books>
    </author>

And i need to store to table Chapter with attributes chapter_name, book_name, author_name. So in this case i should have 5 rows in my table:

Chapter1|Book1|Author1

Chapter2|Book1|Author1

Chapter1|Book2|Author1

Chapter2|Book2|Author1

Chapter3|Book2|Author1

 

If i will just put loop on chapter element i will get al the chapters but i wont get info from which book and author it was.

Anonymous
Not applicable

If you give the loop in the chapter then all the attributes will come.0683p000009MZvJ.png

And the output you will get

0683p000009MZrs.png

 

Don't forget to give kudos/accept the solution when a replay is helpful.