I receive a string from an external java class which is an xml-file. How can I parse this to an ivy-xml object? (Xpert.ivy 4.3)

asked 18.10.2013 at 11:25

Nikel%20Weis's gravatar image

Nikel Weis
accept rate: 57%

The following ivyScript parses an xml stored in string to an ivy-xml object:

String xmlDocument = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <role> <identifier>Everybody</identifier> </role>";
Xml xml = new Xml(xmlDocument);

answered 18.10.2013 at 16:32

Reto%20Weiss's gravatar image

Reto Weiss ♦♦
accept rate: 74%

Which import(s) is/are necessary? I get an class Xml not found message. I've used a different approach using the DocumentBuilder. So I get an xml-Object which is no ivy-object which is actually fine for me. Ah - just to mention - this project is in an 4.3 environment. Beside that - is the role node necessary or was this just an example?

(21.10.2013 at 08:25) Nikel Weis Nikel%20Weis's gravatar image

There is no import necessary because Xml is a standard Xpert.ivy data type. The xml in xmlDocument is an expamle. Your Xml will look different of course. I have written the example code in Xpert.ivy 5. But it should also work in 4.3.

(21.10.2013 at 08:29) Reto Weiss ♦♦ Reto%20Weiss's gravatar image

True. Don't know what was wrong - copy&paste is sometimes a really difficult task for me. ;)

(21.10.2013 at 09:19) Nikel Weis Nikel%20Weis's gravatar image

If an XML-Object (not an ivy-scripting object) is fine for you - which works in my case - I used the following approach:

import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

String xmlString = geoCode.getXML();

DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder db;

db = dbfac.newDocumentBuilder();
Document xmlDoc = db.parse(new InputSource(new StringReader(xmlString)));

answered 21.10.2013 at 08:29

Nikel%20Weis's gravatar image

Nikel Weis
accept rate: 57%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 18.10.2013 at 11:25

Seen: 2,781 times

Last updated: 21.10.2013 at 09:19