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 7438325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:32:14+00:00 2026-05-29T10:32:14+00:00

I have an inventory record XML file to store the quantity of each item.

  • 0

I have an inventory record XML file to store the quantity of each item.

<Inventory>
<Item>
    <ManufacturerName>Brand1</ManufacturerName>
    <ProductType>TV</ProductType>
    <Quantity>146</Quantity>
</Item>
<Item>
    <ManufacturerName>Brand2</ManufacturerName>
    <ProductType>TV</ProductType>
    <Quantity>221</Quantity>
</Item>
<Item>
    <ManufacturerName>Brand3</ManufacturerName>
    <ProductType>TV</ProductType>
    <Quantity>36</Quantity>
</Item>
</Inventory>

In my java program, if I get a request for a certain item, I check the quantity of items of that type remaining (Quantity parameter) and, if there are enough, subtract that amount from the XML file. I can do this by looping through each node of the XML and checking the one I want, but I was hoping there was a faster way of accessing one particular node right away. Maybe the structure of the XML file can be changed to make it more accessible but I can’t think of one.

  • 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-29T10:32:15+00:00Added an answer on May 29, 2026 at 10:32 am

    What you are looking for is XPath, here is a small sample:

    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.xpath.XPath;
    import javax.xml.xpath.XPathConstants;
    import javax.xml.xpath.XPathExpression;
    import javax.xml.xpath.XPathFactory;
    
    import org.w3c.dom.Document;
    import org.w3c.dom.NodeList;
    
    public class GetAllTheChildren {
        public static void main(String[] args) {
        
            try{
                DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
                documentBuilderFactory.setNamespaceAware(true);
                DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
                Document doc = builder.parse("/home/eugen/Desktop/input.txt");
                
                XPathFactory xPathFactory = XPathFactory.newInstance();
                XPath xpath = xPathFactory.newXPath();
            
                XPathExpression expression = xpath.compile("/Inventory/Item[Quantity>200]/*");
            
                NodeList nodes = (NodeList) expression.evaluate(doc, XPathConstants.NODESET);
            
                for(int i = 0;i<nodes.getLength();i++){
                    System.out.println(nodes.item(i).getNodeName());
                    System.out.println(nodes.item(i).getTextContent());
                }
            } catch(Exception exception){
                exception.printStackTrace();
            }
        }
    }
    

    You probably need to play a bit more with it

    Cheers, Eugene.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this the catalog.xml file. I have two books who have the same inventory
I have the following XML :- <inventory> <item> <name_element> <!--some structure--> </name_element> <some_element1>val1</some_element1> <some_element2>val2</some_element2>
Building an inventory system. I have lots of products and each product has three
We currently have a process where we receive an inventory file from a vendor
I have the following fields: Inventory control (16 byte record) Product ID code (int
I have a table with inventory records and another table with documents describing each
I have a CSV file with information about our inventory that gets changed locally
Our current database layout for store inventory includes a table that houses a record
I have a table containing inventory ID | Product ID | In_Transit | Quantity
I have a text file with about 200 item numbers and descriptions, which is

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.