on 02-21-2007 10:57 AM
Hello everyone ,
I have a xml formated string . the inhalt is,
String xml = "
<version-data>
<version-label/>
<payload type="BF">
<businessForm id="BFQuestion 1" BO="CAG_QUESTIONNAIRE" guid="25057326DBA9B14DA7D1B145B4E97E2D" timestamp="2007-02-21T09:30:05.4210000" >
<text spras="EN" text="aaa"/>
................................
</businessForm>
</payload>
</version-data>
";
i want to find the value of a attribute in this String.
e.g. guid="25057326DBA9B14DA7D1B145B4E97E2D"
i wanna get the value 25057326DBA9B14DA7D1B145B4E97E2D of attribute guid.
how can i do?
Thx in advance.
Regards.
Yaning
Hi,
You can parse this XML string using either the DOM/SAX APIs. The code looks like this:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = factory.newDocumentBuilder();
Document doc = documentBuilder.parse(new InputSource(new StringReader(XMLString)));
NodeList nlist=doc.getElementsByTagName("businessForm");
String attrVal = nlist.item(0).getAttributes().getNamedItem("guid").getNodeValue();
Regards,
Satyajit.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The simplest way:
int i = xml.indexOf("guid=\"");
if (i >= 0) {
int j = xml.indexOf("\"", i + "guid=\"".length());
if (j >= 0) {
String result = xml.substring(i, j);
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You can use DOM parser or Pattern class.
In case of Pattern Class, split function should help.
For DOM Parser,something like this
var parser = new DOMParser();
var doc = parser.parseFromString("<items><item name='Apple'/><items>", "text/xml");
Once parsed, you can read elements ,attributes etc.,
Try this : <a href="http://www.xulplanet.com/tutorials/mozsdk/xmlparse.php">Parse Help</a>
Regards
Bharathwaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.