Just nu i M3-nätverket
Gå till innehåll

hur får man ut taggarna ur xml-koden


stenmule

Rekommendera Poster

Jag undrar hur man får ut namnet på taggarna?

Får ut datat men inte taggarna

 

Java koden:

 

import org.w3c.dom.*;

import javax.xml.parsers.*;

import org.xml.sax.*;

import java.io.IOException;

import java.sql.SQLException;

 

public class readXMLFile {

public readXMLFile() throws SQLException, ClassNotFoundException {

DocumentBuilderFactory factory = null;

DocumentBuilder builder = null;

factory = DocumentBuilderFactory.newInstance();

try {

builder = factory.newDocumentBuilder();

}

catch (ParserConfigurationException pce) {

System.out.println("Undantag ParserConfigurationException i samband med factory.newDocumentBuilder()");

System.exit(1);

}

Document document = null;

try {

document = builder.parse("DRPPerf.xml");

}

catch (SAXException se) {

System.out.println(

"Undantag SAXException i samband med document = builder.parse(\"skivor.xml\");");

System.exit(1);

}

catch (IOException ioe) {

System.out.println("Undantag IOException samband med document = builder.parse(\"slashdot.rss.xml\");");

System.exit(1);

}

 

Node rootNode;

rootNode = document.getDocumentElement();

NodeList list;

list = document.getElementsByTagName("*");

 

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

Node childNode = list.item(i).getFirstChild();

if (childNode != null) {

if (childNode.getNodeType() == Node.TEXT_NODE) {

System.out.println("TextContent " +

childNode.getNodeValue());

}

}

}

}

}

 

 

XML-fil:

 

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

<DRPPerf xmlns="http://" xmlns:IR="http://www" >

<IR:GenHead>

<IR:FileCreateDate>2000-12-17T09:30:47-05:00</IR:FileCreateDate>

<IR:IRversion DownwCompat="V 1.2">V 1.2</IR:IRversion>

</IR:GenHead>

<IR:ReportId>String</IR:ReportId>

<IR:StartLogTime>2001-12-17T09:30:47-05:00</IR:StartLogTime>

<IR:EndLogTime>2002-12-17T09:30:47-05:00</IR:EndLogTime>

<DRPPcarrier>

<TimeTag>2011-12-17T09:30:47-05:00</TimeTag>

<TimeRun>2021-12-17T09:30:47-05:00</TimeRun>

</DRPPcarrier>

<DRPPboom>

<TimeTag>1999-12-17T09:30:47-05:00</TimeTag>

<BoomId>100</BoomId>

<LengthDrilled>3.14159</LengthDrilled>

<BoomTimingData>

<TimePos>1999-12-17T10:30:47-05:00</TimePos>

<TimePerc>1999-12-17T11:30:47-05:00</TimePerc>

</BoomTimingData>

</DRPPboom>

<IR:GenTrailer>

<IR:FileCloseDate>2031-12-17T09:30:47-05:00</IR:FileCloseDate>

<IR:ChkSum>A9FD64E12C</IR:ChkSum>

</IR:GenTrailer>

</DRPPerf>

 

/stenmule

 

Länk till kommentar
Dela på andra webbplatser

Arkiverat

Det här ämnet är nu arkiverat och är stängt för ytterligare svar.

×
×
  • Skapa nytt...