1

I have a String variable containing an XML:

String xml = "<?xml version="1.0" encoding="utf-8" standalone="yes"?><CourtactSioux><ListeContact><IdContactClient>212</IdContactClient><DateContact>25/06/2012 08:09</DateContact><TypeForm>STANDARD</TypeForm><Foyer>2</Foyer><Civilite>M</Civilite><Nom>TEST</Nom><Prenom>JULIEN</Prenom><NomJeuneFille></NomJeuneFille></ListeContact></CourtactSioux>"

And I want to take values from this XML, how to do ? For exemple: get "Civilite" value.

I tried this:

                String xml = cn.getXml();
                Integer demandeId = cn.getID();

                XMLParser parser = new XMLParser();
                Document doc = parser.getDomElement(xml); // getting DOM element

                NodeList nl = doc.getElementsByTagName(KEY_ITEM);

// looping through all item nodes <item>
                for (int i = 0; i < nl.getLength(); i++) {
                    Element e = (Element) nl.item(i);
                    idApplication = parser.getValue(e, IdApplication);
                    idContactClient = parser.getValue(e, IdContactClient);
                    logement = parser.getValue(e, Logement);
                    typeForm = parser.getValue(e, TypeForm);
                }

                id = idApplication + idContactClient;

                    Product product =  new Product()
                            .setId(id)
                            .setName(logement)
                            .setCategory(typeForm)
                            .setPrice(1)
                            .setQuantity(1);
                    ProductAction productAction = new ProductAction(ProductAction.ACTION_PURCHASE)
                            .setTransactionId(id)
                            .setTransactionAffiliation("Solutis")
                            .setTransactionRevenue(1);
                    HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder()
                            .addProduct(product)
                            .setProductAction(productAction);

                    Tracker t = ((App) getApplication()).getTracker();
                    t.setScreenName("transaction");
                    t.send(builder.build());
                }

It's work, get attention on the aprent node of your xml

8

1 Answer 1

0

There are several ways of parsing XML in android. You could use XMLReader.parse(InputSource) by wrapping the string in a reader, as shown here

Check the Parsing XML Data part of Android Developers site for more information.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.