I am very new to using XML and I have what should be an easy solution but google is failing me. I have one xml document with different data sets in it (see code below). What I want is to only work with one set of data at a time.

Here is a sample XML doc:

<CATALOG>
  <CD>
	<TITLE>Picture book</TITLE>
	<ARTIST>Simply Red</ARTIST>
	<COUNTRY>EU</COUNTRY>
	<COMPANY>Elektra</COMPANY>
	<PRICE>7.20</PRICE>
	<YEAR>1985</YEAR>
  </CD>

  <CD>
	<TITLE>Red</TITLE>
	<ARTIST>The Communards</ARTIST>
	<COUNTRY>UK</COUNTRY>
	<COMPANY>London</COMPANY>
	<PRICE>7.80</PRICE>
	<YEAR>1987</YEAR>
  </CD>

  <TAPE>
        <TITLE>Unchain my heart</TITLE>
	<ARTIST>Joe Cocker</ARTIST>
	<COUNTRY>USA</COUNTRY>
	<COMPANY>EMI</COMPANY>
	<PRICE>8.20</PRICE>
	<YEAR>1987</YEAR>
  </TAPE>
  <TAPE>
        <TITLE>The dock of the bay</TITLE>
	<ARTIST>Otis Redding</ARTIST>
	<COUNTRY>USA</COUNTRY>
	<COMPANY>Atlantic</COMPANY>
	<PRICE>7.90</PRICE>
	<YEAR>1987</YEAR> 
  </TAPE>
</CATALOG>

In the above example I would like to extract the data sets that are in the CD category first and the TAPE category second. How do I do this? I am able to parse the entire XML doc into an array that I can access using standard array syntax (i.e. xmlChildren[1]). But that gives me only one node or one specific title, how do I restrict to a specific type? Is there some way using the XML DOM to only reference a specific type?

Any suggestion or comment, or question would be greatly appreciated!

Recommended Answers

All 2 Replies

Ok I think the answer is to use XSLT to sort the items I want..... I said I was new! Sorry for the dumb question!!!

Ok I think the answer is to use XSLT to sort the items I want..... I said I was new! Sorry for the dumb question!!!

Words I like to live by...
The only stupid question is the one that isn't asked.
Ask a question to judge yourself of your understanding.

Did you get it working? :) (I'm currently working on something similar, and I want to nest them, but I'm having trouble with the links...) I'm assuming you didn't have links between cases...? I'm debating on whether I should post about it o_o;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.