SelectNodes (Extracting data XML File)

This is a discussion on SelectNodes (Extracting data XML File) within the C++ Programming forums, part of the General Programming Boards category; Hi, I using SelectNodes to extract data from an xml file. Using the code below I can extract the data ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    9

    SelectNodes (Extracting data XML File)

    Hi,

    I using SelectNodes to extract data from an xml file.
    Using the code below I can extract the data i.e. the prices for a particular category:

    XmlDocument *doc = new XmlDocument();

    XmlNodeList *prodNodes;

    prodNodes = doc->SelectNodes("/PRODUCTS/FRUIT[CATEGORY= 'Orange' ]/PRICE");

    However, when I try using a variable with SelectNodes it does not seem to work, therefore what is the correct syntax to use (C++).

    i.e.

    String * selectedItem = FoodCategoryLstBox->SelectedItem.ToString();


    messageNodes = prodNodes->SelectNodes("/PRODUCTS / FRUIT [CATEGORY = ‘selectedItem' ]/PRICE");

    Thanks for your help!

  2. #2
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630
    What is SelectNodes?

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    More intresting is what is String
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    C++/CLI?

    If so, this isn't the forum for you, it is safe to assume that we wont be able to help you.

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    This might work.
    Code:
    String * selectedItem = FoodCategoryLstBox->SelectedItem.ToString();
    
    String * query = String::Format(S"/PRODUCTS / FRUIT [CATEGORY = ‘{0}' ]/PRICE", selectedItem);
    
    messageNodes = prodNodes->SelectNodes(query);

  6. #6
    Registered User
    Join Date
    Jan 2007
    Posts
    9
    Hi anonytmouse,

    Thanks for your help, unfortunately I couldn’t get it to work , However, I have now used the following which works:

    XmlDocument *doc = new XmlDocument();

    XmlNodeList *prodNodes;

    String * selectedItem = FoodCategoryLstBox->SelectedItem.ToString();

    String *query = query ->Concat("/PRODUCTS /FRUIT [CATEGORY ='", selectedItem, "']/PRICE");

    prodNodes = doc ->SelectNodes(query);



    However, I use SelectNodes elsewhere in my program see below:
    ….

    String * selectedItem = FoodCategoryLstBox->SelectedItem.ToString();

    String *Item= ItemcmbBox->SelectedItem->ToString();

    String * query = query ->Concat("/PRODUCTS / FRUIT [CATEGORY ='", selectedItem, "' and ITEM= '", Item, "']/PRICE ");

    Although I cant seem to get this to work using Concat.

    I tried it using C# and I can get it working using the following syntax:

    doc.SelectNodes("/PRODUCTS/FRUIT [CATEGORY= '" + FoodCategoryLstBox.SelectedItem.ToString() + "' and ITEM = '" + ItemcmbBox.SelectedItem.ToString() + "']/ PRICE ");

    But I can’t get working under C++.

    Would anyone know what I’m doing wrong?

    Thanks in advance!

  7. #7
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    What is Ctring?
    in C++ you can use string class to concat substrings with +
    Code:
    string query ("/PRODUCTS / FRUIT [CATEGORY ='");
    query += selectedItem;
    query += "' and ITEM= '";
    query += Item;
    query += "']/PRICE ";
    doc.SelectNodes(query.c_str());
    something like that
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  8. #8
    Registered User
    Join Date
    Jan 2007
    Posts
    9
    Vart String is part of .NET as I'm using WindowsForms

  9. #9
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    I'm not familar with the .Net
    But what I see in the sample looks like
    Code:
    doc.SelectNodes(String::Concat({"/PRODUCTS/FRUIT [CATEGORY= '", FoodCategoryLstBox.SelectedItem.ToString(), "' and ITEM = '" , ItemcmbBox.SelectedItem.ToString() , "']/ PRICE "}));
    Have you tried this?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  10. #10
    Registered User
    Join Date
    Jan 2007
    Posts
    9
    error C2958: the left parenthesis '(' found at ....... was not matched correctly

    thats the error it gives me when using your code

    thanks for your help anyway vart

  11. #11
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    Maybe you should try then
    Code:
    String^ query = String::Concat("/PRODUCTS/FRUIT [CATEGORY= '", FoodCategoryLstBox.SelectedItem.ToString(), "' and ITEM = '" , ItemcmbBox.SelectedItem.ToString() , "']/ PRICE ");
    doc.SelectNodes(query);
    I don't think it is too hard to find a correct syntax... As I see the problem is in the building the correct string, not in the SelectNodes function
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  12. #12
    Registered User
    Join Date
    Jan 2007
    Posts
    9
    Vart I tried but it gives me the following error:
    error C2665: 'System::String::Concat' : none of the 9 overloads can convert parameter 1 from type 'const char [30]'

    It's pretty frustrating as I know what I want it to do will work but can’t seem to get the right syntax for the string.

  13. #13
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    maybe you should try then the old syntax S"hello"?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  14. #14
    Registered User
    Join Date
    Jan 2007
    Posts
    9
    Hi Vart thanks for all your help, sorry to be a bother could you just show me what I need to write in the Concat string section please?

    Thanks in advance for your help!

  15. #15
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    I've posted a code that was compiled with the VC 2005 Express with no errors, don't think I can find something more... As I said I never worked with the .Net
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. Writing and modifying data in a file
    By Micko in forum C Programming
    Replies: 2
    Last Post: 02-17-2005, 02:42 AM
  5. Editing a data file
    By Strait in forum C++ Programming
    Replies: 7
    Last Post: 02-05-2005, 03:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21