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

  • SEARCH
  • Home
  • 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 9314397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:07:25+00:00 2026-06-19T02:07:25+00:00

Similar issue Having few predefined xml which I kept under res>raw>first.xml now I am

  • 0

Similar issue

Having few predefined xml which I kept under res>raw>first.xml now I am fetch at runtime and displying data like below:

NodeList nodes = MainActivity.commonmethod.GetDocumentFile(ProductActivity.this,_intRowID).getElementsByTagName("string");


for (int i = 0; i < nodes.getLength(); i++) {                           

            Element e = (Element)nodes.item(i);
            e.normalize();

                    _ArrProductName.add( MainActivity.commonmethod.getValue(e, "string"));              
            }

Method For Get XML File(Plist File) Using Document

public Document GetDocumentFile(Context context, int rawID) {
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    builderFactory.setNamespaceAware(true);
    DocumentBuilder builder = null;
    try {
        builder = builderFactory.newDocumentBuilder();

        document = builder.parse(context.getResources().openRawResource(
                rawID));
        document.getDocumentElement().normalize();
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    return document;
}

getValue Method

public String getValue(Element item, String str) {
        NodeList n = item.getElementsByTagName(str);

        try {
            StringWriter sw = new StringWriter(); 
            Transformer serializer = TransformerFactory.newInstance().newTransformer(); 
            serializer.transform(new DOMSource(n.item(0)), new StreamResult(sw));   
            String result = sw.toString(); 

            System.out.println("result="+result);

        } catch (Exception e) {
            e.printStackTrace();
        }

        return CommonMethod.getElementValue(n.item(0));
    }

    public final static String getElementValue(Node elem) {
        Node kid;
        if (elem != null) {
            if (elem.hasChildNodes()) {
                for (kid = elem.getFirstChild(); kid != null; kid = kid
                        .getNextSibling()) {
                    if (kid.getNodeType() == Node.TEXT_NODE) {
                        return kid.getNodeValue();
                    }
                }
            }
        }
        return "";
    }

test.xml

 <?xml version="1.0" encoding="UTF-8"?>

    <array>
       <!-- PrdocuName -->
       <string>Android ICS 4.0™</string>

     <!-- PrdocutDescription -->
       <string>Mobile</string>

       <!-- PrdocuImage -->
       <string>Mobile.png</string>

      <!-- PrdocuAddress -->
       <string>url</string>

        <!-- Conversion -->
       <integer>400</integer>

      <!-- ThicknessNames -->
       <string>skim</string>

       <!-- ThicknessValues -->
       <string>1</string>

      <!-- LongDescription -->
       <string>Android is the market leader in terms of total number of device sold and soon it will be leader in terms of total number of application available in the market.</string>

    </array>

Above entire code work well below 4.0 but not above 4.0, getElementsByTagName` return null result above 4.0.

Result in below 4.0

<?xml version="1.0" encoding="UTF-8"?><string>Android ICS 4.0™</string>

Result in Above 4.0

<?xml version="1.0" encoding="UTF-8"?>

String tag is missing while testing in above 4.0,

  • 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-06-19T02:07:26+00:00Added an answer on June 19, 2026 at 2:07 am

    Finally I achieved, made changes inside getvaluefunction;

    Change code:

    public String getValue(Element item, String str) {
    
    
            String strResponse="";
            Node kid;
            if(item!=null)
            {
                if(item.hasChildNodes())
                {
                    for(kid=item.getFirstChild(); kid!=null; kid =kid.getNextSibling())
                    {
                        if (kid.getNodeType() == Node.TEXT_NODE) {
                            strResponse =kid.getNodeValue();
                            return strResponse;
                        }
                    }
                }else
                {
                    NodeList n = item.getElementsByTagName(str);
                    n = item.getChildNodes();
    
                    if(((Node) n.item(0))!=null)
                    {
                        if(((Node) n.item(0)).getNodeValue() !=null)
                        {
                            strResponse =((Node) n.item(0)).getNodeValue();
                            return strResponse;
                        }else
                        {
                            strResponse ="";
                        }
                    }
    
    
                }
            }
    
    
            return strResponse;
    
        }
    

    Its works perfectly!

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

Sidebar

Related Questions

Although I have read a few previously answered questions regarding a similar issue, I
We are having an issue with our node environment running under high load that
Having a very strange issue with a few creative banners. On some computers when
I am having an issue with a query which returns results that are very
I'm using Heroku for the first time and am having a weird issue. I've
I am having a similar issue to JNI_CreateJavaVM exit code -1? , except that
I'm having a similar issue to The current transaction cannot be committed and cannot
I'm having a similar issue to Anthony Chan's question , and after trying every
I know that there are some threads have a similar issue with this thread.
I have a local site (IIS6, although similar issue with a totally different site

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.