L
lejason
Hi,
I have an XML file that is a list of product models and info. The
list will eventually contain about 100 products, each product having
multiple elements for things like names, specifications,
images...etc. Here is the XML Doc.
<productlist>
<product id="001">
<name>Articulating Boom</name>
<model>Z-40N</model>
<description><![CDATA[ VARIOUS HTML DATA GOES HERE ]]></description>
<specs>
<spec1>SOMETHING</spec1>
<spec2>SOMETHING 2</spec2>
<spec3>SOMETHING 3</spec3>
</specs>
<images>
<img1>none</img1>
<img2>none</img2>
<img3>none</img3>
</images>
<specsheets>
<pdf1>something.pdf</pdf1>
<pdf2>something2.pdf</pdf2>
<pdf3>something3.pdf</pdf3>
</specsheets>
</product>
<product id="002">
<name>Articulating Boom</name>
<model>Z-40N</model>
<description><![CDATA[ VARIOUS HTML DATA GOES HERE ]]></description>
<specs>
<spec1>SOMETHING</spec1>
<spec2>SOMETHING 2</spec2>
<spec3>SOMETHING 3</spec3>
</specs>
<images>
<img1>none</img1>
<img2>none</img2>
<img3>none</img3>
</images>
<specsheets>
<pdf1>something.pdf</pdf1>
<pdf2>something2.pdf</pdf2>
<pdf3>something3.pdf</pdf3>
</specsheets>
</product>
So my question is, how do I navigate to show only the children of the
product that i want selected. For example, if I have a link for
product 002, I want to be able to select the "id" attribute under
"product" where the attribute value is 002, and then only be showing
data for THOSE children.
I have this code that I found and it works fine for showing all the
elements with said name, but again, I want to filter the elements so
that I am only talking to the elements who's parent "product" element
has the attribute value of 002.
<%@ Page language="c#" %>
<%@ Import Namespace="System.Xml" %>
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
content.Text = ReadXML("description");
}
public string ReadXML(string thisInfo)
{
System.Text.StringBuilder sbuilder = new
System.Text.StringBuilder();
XmlTextReader reader = null;
try
{
// load the file from the URL
reader = new XmlTextReader("http://rd3247/NET/product.xml");
object productData = reader.NameTable.Add(thisInfo);
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name.Equals(productData))
{
sbuilder.Append(reader.ReadString());
}
}
}
return sbuilder.ToString();
}
catch(Exception e)
{
Response.Write(e.Message);
return "";
}
finally
{
if (reader!=null)
reader.Close();
}
}
</script>
I have an XML file that is a list of product models and info. The
list will eventually contain about 100 products, each product having
multiple elements for things like names, specifications,
images...etc. Here is the XML Doc.
<productlist>
<product id="001">
<name>Articulating Boom</name>
<model>Z-40N</model>
<description><![CDATA[ VARIOUS HTML DATA GOES HERE ]]></description>
<specs>
<spec1>SOMETHING</spec1>
<spec2>SOMETHING 2</spec2>
<spec3>SOMETHING 3</spec3>
</specs>
<images>
<img1>none</img1>
<img2>none</img2>
<img3>none</img3>
</images>
<specsheets>
<pdf1>something.pdf</pdf1>
<pdf2>something2.pdf</pdf2>
<pdf3>something3.pdf</pdf3>
</specsheets>
</product>
<product id="002">
<name>Articulating Boom</name>
<model>Z-40N</model>
<description><![CDATA[ VARIOUS HTML DATA GOES HERE ]]></description>
<specs>
<spec1>SOMETHING</spec1>
<spec2>SOMETHING 2</spec2>
<spec3>SOMETHING 3</spec3>
</specs>
<images>
<img1>none</img1>
<img2>none</img2>
<img3>none</img3>
</images>
<specsheets>
<pdf1>something.pdf</pdf1>
<pdf2>something2.pdf</pdf2>
<pdf3>something3.pdf</pdf3>
</specsheets>
</product>
So my question is, how do I navigate to show only the children of the
product that i want selected. For example, if I have a link for
product 002, I want to be able to select the "id" attribute under
"product" where the attribute value is 002, and then only be showing
data for THOSE children.
I have this code that I found and it works fine for showing all the
elements with said name, but again, I want to filter the elements so
that I am only talking to the elements who's parent "product" element
has the attribute value of 002.
<%@ Page language="c#" %>
<%@ Import Namespace="System.Xml" %>
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
content.Text = ReadXML("description");
}
public string ReadXML(string thisInfo)
{
System.Text.StringBuilder sbuilder = new
System.Text.StringBuilder();
XmlTextReader reader = null;
try
{
// load the file from the URL
reader = new XmlTextReader("http://rd3247/NET/product.xml");
object productData = reader.NameTable.Add(thisInfo);
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name.Equals(productData))
{
sbuilder.Append(reader.ReadString());
}
}
}
return sbuilder.ToString();
}
catch(Exception e)
{
Response.Write(e.Message);
return "";
}
finally
{
if (reader!=null)
reader.Close();
}
}
</script>