Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7586283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:23:21+00:00 2026-05-30T19:23:21+00:00

This is my XML snippet (it has a root element). <ItemAttributes> <Author>Ellen Galinsky</Author> <Binding>Paperback</Binding>

  • 0

This is my XML snippet (it has a root element).

<ItemAttributes>
    <Author>Ellen Galinsky</Author>
    <Binding>Paperback</Binding>
    <Brand>Harper Paperbacks</Brand>
    <EAN>9780061732324</EAN>
    <EANList>
        <EANListElement>9780061732324</EANListElement>
    </EANList>
    <Edition>1</Edition>
    <Feature>ISBN13: 9780061732324</Feature>
    <Feature>Condition: New</Feature>
    <Feature>Notes: BRAND NEW FROM PUBLISHER! 100% Satisfaction Guarantee. Tracking provided on most orders. Buy with Confidence! Millions of books sold!</Feature>
    <ISBN>006173232X</ISBN>
    <IsEligibleForTradeIn>1</IsEligibleForTradeIn>
    <ItemDimensions>
        <Height Units="hundredths-inches">112</Height>
        <Length Units="hundredths-inches">904</Length>
        <Weight Units="hundredths-pounds">98</Weight>
        <Width Units="hundredths-inches">602</Width>
    </ItemDimensions>
    <Label>William Morrow Paperbacks</Label>
    <ListPrice>
        <Amount>1699</Amount>
        <CurrencyCode>USD</CurrencyCode>
        <FormattedPrice>$16.99</FormattedPrice>
    </ListPrice>
    <Manufacturer>William Morrow Paperbacks</Manufacturer>
    <MPN>006173232X</MPN>
    <NumberOfItems>1</NumberOfItems>
    <NumberOfPages>400</NumberOfPages>
    <PackageDimensions>
        <Height Units="hundredths-inches">120</Height>
        <Length Units="hundredths-inches">880</Length>
        <Weight Units="hundredths-pounds">95</Weight>
        <Width Units="hundredths-inches">590</Width>
    </PackageDimensions>
    <PartNumber>006173232X</PartNumber>
    <ProductGroup>Book</ProductGroup>
    <ProductTypeName>ABIS_BOOK</ProductTypeName>
    <PublicationDate>2010-04-20</PublicationDate>
    <Publisher>William Morrow Paperbacks</Publisher>
    <ReleaseDate>2010-04-20</ReleaseDate>
    <SKU>mon0000013657</SKU>
    <Studio>William Morrow Paperbacks</Studio>
    <Title>Mind in the Making: The Seven Essential Life Skills Every Child Needs</Title>
</ItemAttributes>

There are multiple “ItemAttributes” nodes, each having a different “ProductGroup” node. I want only the first “ItemAttribute” where “ProductGroup” = “book:”

This is my C# code:

    XPathDocument doc = new XPathDocument(sr);
    XPathNavigator nav = doc.CreateNavigator();

    // Compile a standard XPath expression
    XPathExpression expr;
    expr = nav.Compile("//ItemAttributes[contains(ProductGroup, 'Book')]");
    XPathNodeIterator iterator = nav.Select(expr);

    // Iterate on the node set
    try {
        int x = iterator.Count;  //  <----------- count = 0
        while (iterator.MoveNext()) {  //  <-----------  finds nothing!
            XPathNavigator nav2 = iterator.Current.Clone();
            listBox1.Items.Add("price: " + nav2.Value);
        }
    }
    catch (Exception ex) {
        Console.WriteLine(ex.Message);
    }

I know my code isn’t correct, but I don’t understand why the iterator.Count is zero!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:23:23+00:00Added an answer on May 30, 2026 at 7:23 pm

    using System.Xml.Linq

    XDocument xdoc = XDocument.Load(new StringReader(xmlstr)); 
    var foundNode = xdoc
        .Descendants("ItemAttributes")
        .Where(node => node.Element("ProductGroup").Value == "Book")
        .First();
    
    var price = foundNode.Element("ListPrice").Element("FormattedPrice").Value;
    

    –EDIT–

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml.Linq;
    using System.IO;
    
    namespace ConsoleApplication4
    {
        class Program
        {
            static void Main(string[] args)
            {
                string xmlstr = @"
                        <root>
                        <ItemAttributes>
                        <Author>Ellen Galinsky</Author>
                        <Binding>Paperback</Binding>
                        <Brand>Harper Paperbacks</Brand>
                        <EAN>9780061732324</EAN>
                        <EANList>
                        <EANListElement>9780061732324</EANListElement>
                        </EANList><Edition>1</Edition>
                        <Feature>ISBN13: 9780061732324</Feature>
                        <Feature>Condition: New</Feature>
                        <Feature>Notes: BRAND NEW FROM PUBLISHER! 100% Satisfaction Guarantee. Tracking provided on most orders. Buy with Confidence! Millions of books sold!</Feature>
                        <ISBN>006173232X</ISBN>
                        <IsEligibleForTradeIn>1</IsEligibleForTradeIn>
                        <ItemDimensions>
                        <Height Units=""hundredths-inches"">112</Height>
                        <Length Units=""hundredths-inches"">904</Length>
                        <Weight Units=""hundredths-pounds"">98</Weight>
                        <Width Units=""hundredths-inches"">602</Width>
                        </ItemDimensions>
                        <Label>William Morrow Paperbacks</Label>
                        <ListPrice>
                        <Amount>1699</Amount>
                        <CurrencyCode>USD</CurrencyCode>
                        <FormattedPrice>$16.99</FormattedPrice>
                        </ListPrice>
                        <Manufacturer>William Morrow Paperbacks</Manufacturer>
                        <MPN>006173232X</MPN>
                        <NumberOfItems>1</NumberOfItems>
                        <NumberOfPages>400</NumberOfPages>
                        <PackageDimensions>
                        <Height Units=""hundredths-inches"">120</Height>
                        <Length Units=""hundredths-inches"">880</Length>
                        <Weight Units=""hundredths-pounds"">95</Weight>
                        <Width Units=""hundredths-inches"">590</Width>
                        </PackageDimensions>
                        <PartNumber>006173232X</PartNumber>
                        <ProductGroup>Book</ProductGroup>
                        <ProductTypeName>ABIS_BOOK</ProductTypeName>
                        <PublicationDate>2010-04-20</PublicationDate>
                        <Publisher>William Morrow Paperbacks</Publisher>
                        <ReleaseDate>2010-04-20</ReleaseDate>
                        <SKU>mon0000013657</SKU>
                        <Studio>William Morrow Paperbacks</Studio>
                        <Title>Mind in the Making: The Seven Essential Life Skills Every Child Needs</Title>
                        </ItemAttributes>
                        </root>
                        ";
                XDocument xdoc = XDocument.Load(new StringReader(xmlstr));
                var foundNode = xdoc
                    .Descendants("ItemAttributes")
                    .Where(node => node.Element("ProductGroup").Value == "Book")
                    .First();
    
                Console.WriteLine(foundNode.Element("ListPrice").Element("FormattedPrice").Value);
                Console.ReadLine();
    
            }
        }
    }
    

    –EDIT2–

    XDocument xdoc = XDocument.Load("http://ecs.amazonaws.com/onca/xml?AWSAccessKeyId=AKIAIAAFYAPOR6SX5GOA&AssociateTag=pragbook-20&IdType=ISBN&ItemId=9780061732324&MerchantId=All&Operation=ItemLookup&ResponseGroup=Medium&SearchIndex=Books&Service=AWSECommerceService&Timestamp=2012-02-26T20%3A18%3A37Z&Version=2011-08-01&Signature=r7yE7BQI44CqWZAiK%2FWumF3N4iutOj3re9wZtESOaKs%3D");
    XNamespace ns = XNamespace.Get("http://webservices.amazon.com/AWSECommerceService/2011-08-01");
    var foundNode = xdoc
        .Descendants(ns+"ItemAttributes")
        .Where(node => node.Element(ns+"ProductGroup").Value == "Book")
        .First();
    
    Console.WriteLine(foundNode.Element(ns+"ListPrice").Element(ns+"FormattedPrice").Value);
    Console.ReadLine();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The xml file has this snippet: <?xml version=1.0?> <PC-AssayContainer xmlns=http://www.ncbi.nlm.nih.gov xmlns:xs=http://www.w3.org/2001/XMLSchema-instance xs:schemaLocation=http://www.ncbi.nlm.nih.gov ftp://ftp.ncbi.nlm.nih.gov/pubchem/specifications/pubchem.xsd >
given this xml: <root> <list> <!-- foo's comment --> <item name=foo /> <item name=bar
In the code snippet below, I only have 1 element in the XML that
I've got an XML snippet and it has a section where an URL is
This XML file contained archived news stories for all of last year. I was
Given this XML, what XPath returns all elements whose prop attribute contains Foo (the
For this xml (in a SQL 2005 XML column): <doc> <a>1</a> <b ba="1" bb="2"
Given this XML ... <ListBucketResult xmlns=http://s3.amazonaws.com/doc/2006-03-01/> <Name>public.rpmware.com</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> <Contents> <Key>0.dir</Key> <LastModified>2008-06-25T16:09:49.000Z</LastModified>
Given this XML: <?xml version=1.0 encoding=utf-8?> <content dataType=XML> <item type=Promotion name=Sample Promotion expires=04/01/2009> <![CDATA[
Having this XML view: <?xml version=1.0 encoding=utf-8?> <LinearLayout android:id=@+id/myScrollLayout android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical xmlns:android=http://schemas.android.com/apk/res/android> <ScrollView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.