Parse XML with SAX

Hi all, I have the folow xml file:
<n>
<q>
<r></r>
<r></r>
</q>
</n>
How can I make, that automaticli show me the elements of a tree?
for Example:
n includes r,r,q
q includes r,r
r includes r
r includes r
That I can show the Elements of all Trees?
Thanks verry much.

Read this tutorial:
http://java.sun.com/webservices/docs/1.2/tutorial/doc/index.html
It has some examples like that. If I knew what you wanted when you said "show" I could be more specific.

Similar Messages

  • How to Parse XML with SAX and Retrieving the Information?

    Hiya!
    I have written this code in one of my classes:
    /**Parse XML File**/
              SAXParserFactory factory = SAXParserFactory.newInstance();
              GameContentHandler gameCH = new GameContentHandler();
              try
                   SAXParser saxParser = factory.newSAXParser();
                   saxParser.parse(recentFiles[0], gameCH);
              catch(javax.xml.parsers.ParserConfigurationException e)
                   e.printStackTrace();
              catch(java.io.IOException e)
                   e.printStackTrace();
              catch(org.xml.sax.SAXException e)
                   e.printStackTrace();
              /**Parse XML File**/
              games = gameCH.getGames();And here is the content handler:
    import java.util.ArrayList;
    import org.xml.sax.*;
    import org.xml.sax.helpers.DefaultHandler;
    class GameContentHandler extends DefaultHandler
         private ArrayList<Game> games = new ArrayList<Game>();
         public void startDocument()
              System.out.println("Start document.");
         public void endDocument()
              System.out.println("End document.");
         public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes atts) throws SAXException
         public void endElement(String namespaceURI, String localName, String qualifiedName) throws SAXException
         public void characters(char[] ch, int start, int length) throws SAXException
              /**for (int i = start; i < start+length; i++)
                   System.out.print(ch);
         public ArrayList<Game> getGames()
              return games;
    }And here is the xml i am trying to parse:<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
    <Database>
         <Name></Name>
         <Description></Description>
         <CurrentGameID></CurrentGameID>
         <Game>
              <gameID></gameID>
              <name></name>
              <publisher></publisher>
              <platform></platform>
              <type></type>
              <subtype></subtype>
              <genre></genre>
              <serial></serial>
              <prodReg></prodReg>
              <expantionFor></expantionFor>
              <relYear></relYear>
              <expantion></expantion>
              <picPath></picPath>
              <notes></notes>
              <discType></discType>
              <owner></owner>
              <location></location>
              <borrower></borrower>
              <numDiscs></numDiscs>
              <discSize></discSize>
              <locFrom></locFrom>
              <locTo></locTo>
              <onLoan></onLoan>
              <borrowed></borrowed>
              <manual></manual>
              <update></update>
              <mods></mods>
              <guide></guide>
              <walkthrough></walkthrough>
              <cheats></cheats>
              <savegame></savegame>
              <completed></completed>
         </Game>
    </Database>I have been trying for ages and just can't get the content handler class to extract a gameID and instantiate a Game to add to my ArrayList! How do I extract the information from my file?
    I have tried so many things in the startElement() method that I can't actually remember what I've tried and what I haven't! If you need to know, the Game class instantiates with asnew Game(int gameID)and the rest of the variables are public.
    Please help someone...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    OK, how's this?
    public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes atts) throws SAXException
              current = "";
         public void endElement(String namespaceURI, String localName, String qualifiedName) throws SAXException
              try
                   if(qualifiedName.equals("Game") || qualifiedName.equals("Database"))
                        {return;}
                   else if(qualifiedName.equals("gameID"))
                        {games.add(new Game(Integer.parseInt(current)));}
                   else if(qualifiedName.equals("name"))
                        {games.get(games.size()-1).name = current;}
                   else if(qualifiedName.equals("publisher"))
                        {games.get(games.size()-1).publisher = current;}
                   etc...
                   else
                        {System.out.println("ERROR - Qualified Name found in xml that does not exist as databse field: " + qualifiedName);}
              catch (Exception e) {} //Ignore
         public void characters(char[] ch, int start, int length) throws SAXException
              current += new String(ch, start, length);
         }

  • Problem parsing XML with schema when extracted from a jar file

    I am having a problem parsing XML with a schema, both of which are extracted from a jar file. I am using using ZipFile to get InputStream objects for the appropriate ZipEntry objects in the jar file. My XML is encrypted so I decrypt it to a temporary file. I am then attempting to parse the temporary file with the schema using DocumentBuilder.parse.
    I get the following exception:
    org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element '<root element name>'
    This was all working OK before I jarred everything (i.e. when I was using standalone files, rather than InputStreams retrieved from a jar).
    I have output the retrieved XML to a file and compared it with my original source and they are identical.
    I am baffled because the nature of the exception suggests that the schema has been read and parsed correctly but the XML file is not parsing against the schema.
    Any suggestions?
    The code is as follows:
      public void open(File input) throws IOException, CSLXMLException {
        InputStream schema = ZipFileHandler.getResourceAsStream("<jar file name>", "<schema resource name>");
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = null;
        try {
          factory.setNamespaceAware(true);
          factory.setValidating(true);
          factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
          factory.setAttribute(JAXP_SCHEMA_SOURCE, schema);
          builder = factory.newDocumentBuilder();
          builder.setErrorHandler(new CSLXMLParseHandler());
        } catch (Exception builderException) {
          throw new CSLXMLException("Error setting up SAX: " + builderException.toString());
        Document document = null;
        try {
          document = builder.parse(input);
        } catch (SAXException parseException) {
          throw new CSLXMLException(parseException.toString());
        }

    I was originally using getSystemResource, which worked fine until I jarred the application. The problem appears to be that resources returned from a jar file cannot be used in the same way as resources returned directly from the file system. You have to use the ZipFile class (or its JarFile subclass) to locate the ZipEntry in the jar file and then use ZipFile.getInputStream(ZipEntry) to convert this to an InputStream. I have seen example code where an InputStream is used for the JAXP_SCHEMA_SOURCE attribute but, for some reason, this did not work with the InputStream returned by ZipFile.getInputStream. Like you, I have also seen examples that use a URL but they appear to be URL's that point to a file not URL's that point to an entry in a jar file.
    Maybe there is another way around this but writing to a file works and I set use File.deleteOnExit() to ensure things are tidied afterwards.

  • Can I parse non-wellformed XML with SAX at all?

    Hi all,
    i was wondering whether its possible at all to parse XML that is not well formed with SAX.
    e.g. A HTML file that doesnt close tags and stuff like that.
    I tried implementing the fatal() method of the Handler in a a way that it consumes the exception but does not rethrow it.
    Also I tried setting the validation property to false. Both with no success.
    Any help would be appriciated.
    thx
    philipp

    Your experiments tell you the answer.
    If you have HTML tag soup, why not just run it through JTidy or HTMLTidy to make it into well-formed XHTML?

  • How to parse XML using SAX Parser sequencially

    I have a requirement to parse XML file sequencially. But I need to stop the parsing in-between for doing some processing.
    Let me explain with example
    I have a file with following structure.
    <InputFile>
    <Invoice>
         <InvoiceNo = "Inv1"/>
    <InvoiceDt = "12012002"/>
    </Invoice>
    <Invoice>
         <InvoiceNo = "Inv2"/>
    <InvoiceDt = "12012002"/>
    </Invoice>
    <Invoice>
         <InvoiceNo = "Inv3"/>
    <InvoiceDt = "12012002"/>
    </Invoice>
    For each Invoice node I need to process some activites. So I need to write a method which will open the XML file and parse and returns me a complete element from <invoice> to </Invoice> sequencially.
    Please let me know whther some body has solution for this.
    Manoj.

    If you're using a SAX parser then you can implement your code in the startElement(), endElement(), and characters() methods... have a look at the tutorial here:
    http://java.sun.com/xml/jaxp/dist/1.1/docs/tutorial/index.html

  • Parsing XML with DTD residing in jar file

    Hi,
    I have problems using crimson parser for my program under JDK 1.4.0b2. It attempts to parse an xml file with SAX. The corresponding lies in a jar file in a different directory but reachable through the classpath. All I get is an exception.
    org.xml.sax.SAXParseException: Relative URI "my.dtd"; kann nicht ohne eine Dokument-URI aufgel�st werden.
    at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3121)
    at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3115)
    at org.apache.crimson.parser.Parser2.resolveURI(Parser2.java:2702)
    at org.apache.crimson.parser.Parser2.maybeExternalID(Parser2.java:2674)
    at org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Parser2.java:1125)
    at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:489)
    at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
    at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:433)
    at org.xml.sax.helpers.XMLReaderAdapter.parse(XMLReaderAdapter.java:223)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:326)
    I used Xerces before and it worked fine. I already searched the community for that problem. All hints I found assume that xml file and dtd are in the same directory. Setting the systemId of the input source doesn't fix the problem.
    Is there anyone out there knowing what to do?
    Thanks,
    Thorsten

    Use a Resolver to map a PUBLIC name to a local name:
    <!DOCTYPE DOC PUBLIC "-//gaskin.de//XMLDOC 1.0//EN"
    "http://www.gaskin.de/dtd/xmldoc.dtd">
    public static register() {
       ClassLoader loader = Resolver.class.getClassLoader();
       registerCatalogEntry(
          "-//gaskin.de//XMLDOC 1.0//EN",
          "de/gaskin/resources/dtd/XMLDOC.DTD",
          loader);
    }

  • Parse htmlentites with SAX

    I am getting the following exception when I to parse an xml document (as a String) containg htmlentities:
    org.xml.sax.SAXParseException: The entity "Atilde" was referenced, but not declared.for
    <?xml version="1.0" encoding="UTF-8" ?><id="123" path="/bj&Atilde;&para;rk/">
    ...the code looks like:
    InputSource input = new InputSource();
    input.setCharacterStream(new StringReader(theXMLString));
    reader.parse(input);Is there a way to make SAX aware of those htmlentities?

    I am running into the same problem while trying to parse XML data from Yahoo Shopping web services for my price comparison mashup
    xatori.com. The exception I am getting is:
    org.jdom.input.JDOMParseException: Error on line 80: The entity "Atilde" was referenced, but not declared.
         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:504)
         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:807)
         at com.abc.xyz(yhoo.java:39)
    Caused by: org.xml.sax.SAXParseException: The entity "Atilde" was referenced, but not declared.
         at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
         at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanAttributeValue(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanAttribute(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
         at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
         at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
         at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
         at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
         at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:489)
         ... 2 moreThis happens only with specific (random) search queries...thoughts?

  • Persisting unexplained errors when parsing XML with schema validation

    Hi,
    I am trying to parse an XML file including XML schema validation. When I validate my .xml and .xsd in NetBeans 5.5 beta, I get not error. When I parse my XML in Java, I systematically get the following errors no matter what I try:
    i) Document root element "SQL_STATEMENT_LIST", must match DOCTYPE root "null".
    ii) Document is invalid: no grammar found.
    The code I use is the following:
    try {
    Document document;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    document = builder.parse( new File(PathToXml) );
    My XML is:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <!-- Defining the SQL_STATEMENT_LIST element -->
    <xs:element name="SQL_STATEMENT_LIST" type= "SQL_STATEMENT_ITEM"/>
    <xs:complexType name="SQL_STATEMENT_ITEM">
    <xs:sequence>
    <xs:element name="SQL_SCRIPT" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    <!-- Defining simple type ApplicationType with 3 possible values -->
    <xs:simpleType name="ApplicationType">
    <xs:restriction base="xs:string">
    <xs:enumeration value="DawningStreams"/>
    <xs:enumeration value="BaseResilience"/>
    <xs:enumeration value="BackBone"/>
    </xs:restriction>
    </xs:simpleType>
    <!-- Defining the SQL_SCRIPT element -->
    <xs:element name="SQL_SCRIPT" type= "SQL_STATEMENT"/>
    <xs:complexType name="SQL_STATEMENT">
    <xs:sequence>
    <xs:element name="NAME" type="xs:string"/>
    <xs:element name="TYPE" type="xs:string"/>
    <xs:element name="APPLICATION" type="ApplicationType"/>
    <xs:element name="SCRIPT" type="xs:string"/>
    <!-- Making sure the following element can occurs any number of times -->
    <xs:element name="FOLLOWS" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    </xs:schema>
    and my XML is:
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    Document : SQLStatements.xml
    Created on : 1 juillet 2006, 15:08
    Author : J�r�me Verstrynge
    Description:
    Purpose of the document follows.
    -->
    <SQL_STATEMENT_LIST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://www.dawningstreams.com/XML-Schemas/SQLStatements.xsd">
    <SQL_SCRIPT>
    <NAME>CREATE_PEERS_TABLE</NAME>
    <TYPE>CREATION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    CREATE CACHED TABLE PEERS (
    PEER_ID           VARCHAR(20) NOT NULL,
    PEER_KNOWN_AS      VARCHAR(30) DEFAULT ' ' ,
    PRIMARY KEY ( PEER_ID )
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>CREATE_COMMUNITIES_TABLE</NAME>
    <TYPE>CREATION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    CREATE CACHED TABLE COMMUNITIES (
    COMMUNITY_ID VARCHAR(20) NOT NULL,
    COMMUNITY_KNOWN_AS VARCHAR(25) DEFAULT ' ',
    PRIMARY KEY ( COMMUNITY_ID )
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>CREATE_COMMUNITY_MEMBERS_TABLE</NAME>
    <TYPE>CREATION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    CREATE CACHED TABLE COMMUNITY_MEMBERS (
    COMMUNITY_ID VARCHAR(20) NOT NULL,
    PEER_ID VARCHAR(20) NOT NULL,
    PRIMARY KEY ( COMMUNITY_ID, PEER_ID )
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>DROP_PEER_TABLE</NAME>
    <TYPE>DELETION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    DROP TABLE PEERS IF EXISTS
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>DROP_COMMUNITIES_TABLE</NAME>
    <TYPE>DELETION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    DROP TABLE COMMUNITIES IF EXISTS
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>DROP_COMMUNITY_MEMBERS_TABLE</NAME>
    <TYPE>DELETION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    DROP TABLE COMMUNITY_MEMBERS IF EXISTS
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>CREATE_COMMUNITY_MEMBERS_VIEW</NAME>
    <TYPE>CREATION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    CREATE VIEW COMMUNITY_MEMBERS_VW AS
    SELECT P.PEER_ID, P.PEER_KNOWN_AS, C.COMMUNITY_ID, C.COMMUNITY_KNOWN_AS
    FROM PEERS P, COMMUNITIES C, COMMUNITY_MEMBERS CM
    WHERE P.PEER_ID = CM.PEER_ID
    AND C.COMMUNITY_ID = CM.COMMUNITY_ID
    </SCRIPT>
    <FOLLOWS>CREATE_PEERS_TABLE</FOLLOWS>
    <FOLLOWS>CREATE_COMMUNITIES_TABLE</FOLLOWS>
    </SQL_SCRIPT>
    </SQL_STATEMENT_LIST>
    Any ideas? Thanks !!!
    J�r�me Verstrynge

    Hi,
    I found the solution in the following post:
    Validate xml with DOM - no grammar found
    Sep 17, 2003 10:58 AM
    The solution is to add a line of code when parsing:
    try {
    Document document;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);
    factory.setNamespaceAware(true);
    factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
    DocumentBuilder builder = factory.newDocumentBuilder();
    document = builder.parse( new File(PathToXml) );
    The errors are gone !!!
    J�r�me Verstrynge

  • Parsing XML with invalid URI for DTD

    When parsing an XML file (with aelfred2) I get the following error:
    Exception in thread "main" gnu.xml.dom.ls.DomLSException: Absolute URL required with null context: CQCGWProtocol.DTD
    at gnu.xml.dom.ls.DomLSParser.doParse(libgcj.so.7)
    at gnu.xml.dom.ls.DomLSParser.parse(libgcj.so.7)
    at gnu.xml.dom.DomDocumentBuilder.parse(libgcj.so.7)
    at CQC.main(CQC.java:44)
    Caused by: java.net.MalformedURLException: Absolute URL required with null context: CQCGWProtocol.DTD
    at java.net.URL.<init>(libgcj.so.7)
    at java.net.URL.<init>(libgcj.so.7)
    at gnu.xml.aelfred2.XmlParser.pushURL(libgcj.so.7)
    at gnu.xml.aelfred2.XmlParser.parseDoctypedecl(libgcj.so.7)
    at gnu.xml.aelfred2.XmlParser.parseProlog(libgcj.so.7)
    at gnu.xml.aelfred2.XmlParser.parseDocument(libgcj.so.7)
    I'm puzzled, as I have disabled validation:
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setIgnoringComments(true);
    domFactory.setNamespaceAware(false);
    domFactory.setValidating(false);
    My goal is to have the parser ignore the DOCTYPE tag and not try to find the DTD. Can someone suggest how you turn this off - apparently, setting the validation to false is not the right approach.
    I'm running Java 1.4.2 on Fidora Core 5.
    Thanks for suggestions!

    Create an org.xml.sax.EntityResolver and apply it to your parser. The API documentation for the interface has an example of how to write one.
    And no, turning of validation doesn't turn off processing of DTDs because DTDs are for things other than validation. Entity replacement, for example.

  • Parsing xml with dom4j - cannot find jar file

    Hi,
    I'm using Jdeveloper 10g and tomcat 5.5.9. I have a servlet which calls a java class (ParseXML.java) that trys to parse an xml string using dom4j. A snippet of ParseXML.java...
    import org.dom4j.Document;
    import org.dom4j.DocumentException;
    import org.dom4j.io.SAXReader;
    public class ParseXML  {
    public ParseXML(String xml) {
              this.XML_STRING = xml;
         public String parse() {
              SAXReader reader = new SAXReader();
              Document document = null;
              try  {
                   document = reader.read(XML_STRING);
                   } catch (DocumentException de)  {
                   return de.getMessage();
              } catch (Exception e) {
                   return e.getMessage();
                   return "The xml root value is: " + document.getRootElement().getName();
    } I've downloaded the dom4j 1.6.1 jar and put it on the project class path (specified in the jdev project proerties), and my code also compiles ok. But when i try to instantiate ParseXML from my servlet i get a runtime exception:
    javax.servlet.ServletException: Servlet execution threw an exception
    root cause
    java.lang.NoClassDefFoundError: org/dom4j/DocumentException
         arcims.GetMapServlet.doPost(GetMap.java:45)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802I'm not sure if this is a class path issue or something else; i've checked and rechecked the classpath and nothing seems amiss.
    Suggestions, anyone?

    Question: Is it really necessary to use a
    StringReader if my xml document is not saved to disk?
    I get XML_STRING from a web service, convert it into
    a xml document so i can manipulate/parse it, but then
    i don't save the document, i just discard it. How
    does my system's default character set affect string
    manipulations that i do within my java app?Your system's default charset doesn't have anything to do with string manipulations, if by that you mean substrings and concatenations of strings. It is used when you convert strings to bytes and bytes to strings. If your string contains a character that can't be handled by your default charset, then converting that string to bytes will put ? in place of that character. Converting those bytes back to a string will leave the ? as is. Thus your string has been changed.
    Also converting the string to bytes can have bad results, because the first thing the XML parser does is to convert the bytes back to a string, using the charset declared in the XML. If this charset is different from your system's default, then your XML may be corrupted by this process if it contains characters that are encoded differently in the two charsets. The typical example of this is European accented letters like �, which are encoded differently in ISO-8859-1 or Windows-1252 (most people's default charsets) and UTF-8 (the default XML charset).
    Besides, converting the string to bytes just so it can be immediately converted back to a string is rather wasteful.

  • Parsing XML with VBS at a Windows Server 2008 R2

    Hi
    my name is Marius, and I have a little problem with my vbs script. I use this script to parse an xml File if there are errors inside. In my old environment Windows Server 2003 it would work fine.
    Now I will run this script at a newer Server 2008 R2, and it is not working.
    Dim sName
    sName = "Path to xml file"
    Dim xmlFile
    Dim oneNode
    Dim childNodes, childNode
    Dim attribut
    Dim EventID
    Dim repGroup
    Dim CustomDomain
    Dim ErrorCounter
    BackupNotes = ""
    ErrorCounter = 0
    wscript.Echo "sName: " & sName 'Wird in die Logdatei geschrieben
    set xmlFile = CreateObject("Microsoft.XMLDOM")
    'Es wird die XML Datei geladen
    if xmlFile.load(sName) then
    'Schreibt das Datum und die Uhrzeit des XML Datei in oneNode
    set oneNode = xmlFile.selectSingleNode("//timestamp/systemTime")
    if oneNode is Nothing then
    BackupBeginTime = ""
    BackupEndTime = ""
    BackupBeginDate = ""
    BackupEndDate = ""
    'wscript.echo "Keine Daten vorhanden" 'Wird in die Logdatei geschrieben
    else
    'Friday, November 09, 2012 11:55:32
    BackupBeginTime = right(oneNode.text, 8)
    'nimm von rechts die 8 folgenden Zeichen (11:55:32)
    BackupEndTime = BackupBeginTime
    Dim Laenge
    Laenge = LEN(oneNode.text)
    'zaehlt die Lange des Strings in oneNode 'Friday, November 09, 2012 11:55:32 = 34
    'wscript.echo Laenge
    Laenge = Laenge - 9
    '34 - 9 = 25
    'es wird das Datum aus dem String der XML Datei gebaut, damit es in die DB geschrieben werden kann
    Dim dfsDate
    Dim dfsVon
    Dim dfsBis
    dfsDate = left(oneNode.text, Laenge)
    'nimm von links die 25 folgenden Zeichen (Friday, November 09, 2012)
    dfsVon = inStr(dfsDate, ",")
    'pruefe wo das 1. Komma ist und schreiben die Zeichen in die Variable
    dfsVon = dfsVon + 1
    'wscript.echo dfsVon
    dfsBis = LEN(dfsDate)
    'wscript.echo dfsBis
    dfsDate = mid(dfsDate, dfsVon, dfsBis)
    'Nimm die daten ab dem Komme bis zum Ende des Strings
    dfsDate = trim(dfsDate)
    'entferne die Leerzeichen Vor und Nach dem Sting
    'Wscript.echo dfsDate
    dfsDate = cdate(dfsDate)
    'dfsDate = November 09, 2012 und wird in 09.11.2012 durch cdate umgebaut
    'wscript.echo dfsDate
    BackupBeginDate = dfsDate
    BackupEndDate = dfsDate
    end if
    set oneNode = xmlFile.selectSingleNode("//replicationGroup")
    'Sucht nach der Replikationsgruppe und der Domain
    repGroup = oneNode.getAttribute("name")
    CustomDomain = oneNode.getAttribute("domain")
    if oneNode is Nothing then
    wscript.echo "Keine Daten vorhanden"
    'Wird in die Logdatei geschrieben
    else
    wscript.echo "RepGroup: " & repGroup
    'holt sich den Namen der Replikations Gruppe 'Wird in die Logdatei geschrieben
    wscript.echo "Domain: " & CustomDomain
    'holt sich den Domain 'Wird in die Logdatei geschrieben
    end if
    set childNodes = xmlFile.selectNodes("//serverErrors/error")
    for each childNode in childNodes
    'Zugriff auf den Type und die Event ID
    attribut = childNode.getAttribute("type")
    EventID = childNode.getAttribute("id")
    if isNull(attribut) then
    wscript.echo "MultiParameter nicht gefunden" 'Wird in die Logdatei geschrieben
    'Fehlerhandling, da attribut nicht vorhanden
    'wenn keines dieser Attribute vorhanden ist, ist der Backupjob erfolgreich
    ErrorCounter = 0
    else
    ' pruefen was im attribut steht und dann entscheiden ob erfolgreich oder nicht
    if(attribut = "error") then
    if(EventID = "6002") then
    BackupNotes = BackupNotes & " "& attribut &"("& EventID &")"
    wscript.echo "EventID: "& attribut &" ("& EventID & ") - http://support.microsoft.com/kb/953527" 'Wird in die Logdatei geschrieben
                   'Fehlerbehandlung mit ErrrorCounter - Fehler bekannt = 0 Fehler unbekannt + 1
                    ErrorCounter = ErrorCounter + 1
    elseif(EventID = "11004") then
    BackupNotes = BackupNotes & " "& attribut &"("& EventID &" - Temp File)"
    wscript.echo "EventID: "& attribut &" ("& EventID & ") - Es konnten nicht alle Daten kopiert werden, Temporaere Dateien http://social.technet.microsoft.com/wiki/contents/articles/406.dfsr-does-not-replicate-temporary-files.aspx"
    'Wird in die Logdatei geschrieben
                   'Fehlerbehandlung mit ErrrorCounter - Fehler bekannt = 0 Fehler unbekannt + 1
                    ErrorCounter = ErrorCounter + 0
    elseif(EventID = "4302") then
    BackupNotes = BackupNotes & " "& attribut &"("& EventID &" - Freigabeverletzung)"
    wscript.echo "EventID: "& attribut &" ("& EventID & ") - Freigabeverletzung http://support.microsoft.com/kb/973836 - Fehler ist bekannt und kann ignoriert werden" 'Wird in die
    Logdatei geschrieben
                   'Fehlerbehandlung mit ErrrorCounter - Fehler bekannt = 0 Fehler unbekannt + 1
                    ErrorCounter = ErrorCounter + 0
    elseif(EventID = "4208") then
    BackupNotes = BackupNotes & " "& attribut &"("& EventID &" - Staging Quota)"
    wscript.echo "EventID: "& attribut &" ("& EventID & ") - Staging Quota zu klein http://blogs.technet.com/b/askds/archive/2011/07/13/how-to-determine-the-minimum-staging-area-dfsr-needs-for-a-replicated-folder.aspx"
    'Wird in die Logdatei geschrieben
                   'Fehlerbehandlung mit ErrrorCounter - Fehler bekannt = 0 Fehler unbekannt + 1
                    ErrorCounter = ErrorCounter + 1
    else
    BackupNotes = BackupNotes & " "& attribut &"("& EventID &")"
    wscript.echo "EventID: "& attribut &" ("& EventID & ")"  'Wird in die Logdatei geschrieben
                   'Fehlerbehandlung mit ErrrorCounter - Fehler bekannt = 0 Fehler unbekannt + 1
                    ErrorCounter = ErrorCounter + 1
    end if
    end if
    if(attribut = "warning") then
    if (EventID = "4208") then
    BackupNotes = BackupNotes & " "& attribut &"("& EventID &" - Staging Quota)"
    wscript.echo "EventID: "& attribut &" ("& EventID & ") - Staging Quota zu klein http://www.retherfords.com/blogs/CoryRetherford/Lists/Posts/Post.aspx?ID=104 - Fehler ist bekannt und
    kann ignoriert werden"  'Wird in die Logdatei geschrieben
    'Fehlerbehandlung mit ErrrorCounter - Fehler bekannt = 0 Fehler unbekannt + 1
    ErrorCounter = ErrorCounter + 0
    elseif (EventID = "11004") then
    BackupNotes = BackupNotes & " "& attribut &"("& EventID &" - Temp Datei)"
    wscript.echo "EventID: "& attribut &" ("& EventID & ") - Es konnten nicht alle Daten kopiert werden, Temporaere Dateien - Fehler ist bekannt und kann ignoriert werden"  'Wird
    in die Logdatei geschrieben
    'Fehlerbehandlung mit ErrrorCounter - Fehler bekannt = 0 Fehler unbekannt + 1
    ErrorCounter = ErrorCounter + 0
    elseif (EventID = "4302") then
    BackupNotes = BackupNotes & " "& attribut &"("& EventID &" - Freigabeverletzung)"
    wscript.echo "EventID: "& attribut &" ("& EventID & ") - Freigabeverletzung http://support.microsoft.com/kb/973836 - Fehler ist bekannt und kann ignoriert werden"  'Wird
    in die Logdatei geschrieben
    'Fehlerbehandlung mit ErrrorCounter - Fehler bekannt = 0 Fehler unbekannt + 1
    ErrorCounter = ErrorCounter + 0
    elseif (EventID = "4206") then
    BackupNotes = BackupNotes & " "& attribut &"("& EventID &" - Staging Quota)"
    wscript.echo "EventID: "& attribut &" ("& EventID & ") - Staging Quota zu klein http://mpwiki.viacode.com/default.aspx?g=posts&t=123818"  'Wird in die Logdatei geschrieben
    'Fehlerbehandlung mit ErrrorCounter - Fehler bekannt = 0 Fehler unbekannt + 1
    ErrorCounter = ErrorCounter + 0
    elseif (EventID = "11001") then
    BackupNotes = BackupNotes & " "& attribut &"("& EventID &" -)"
    wscript.echo "EventID: "& attribut &" ("& EventID & ") - "  'Wird in die Logdatei geschrieben
    'Fehlerbehandlung mit ErrrorCounter - Fehler bekannt = 0 Fehler unbekannt + 1
    ErrorCounter = ErrorCounter + 0
    else
    BackupNotes = BackupNotes & " "& attribut &"("& EventID &")"
    wscript.echo "EventID: "& attribut &" ("& EventID & ")"  'Wird in die Logdatei geschrieben
    'Fehlerbehandlung mit ErrrorCounter - Fehler bekannt = 0 Fehler unbekannt + 1
    ErrorCounter = ErrorCounter + 0
    end if
    end if
    end if
    next
    else
    wscript.echo "Pfad (sName): XML Datei nicht vorhanden" 'Wird in die Logdatei geschrieben
    ErrorCounter = ErrorCounter + 1
    'Wenn keine XML Datei vorhanden ist, wird dies in die DB geschrieben
    BackupBeginTime = ""
    BackupEndTime = ""
    BackupBeginDate = ""
    BackupEndDate = ""
    BackupNotes = "XML Datei nicht vorhanden"
    end if
    Had somebody a Info for me what I'm doing wrong :)
    Thanks & Regards
    Marius

    Hi JRV,
    I have checked my script und I have get it running by wscript.
    And I have an error with the funktion cdate:
    sName: \\S-49-NICSAS-201.nicsas.local\_logs\RH\S-49-RHBAD-001\DFS\S-49-RHBAD-001-Bad_Users.xml
    10
    27
    December 19, 2013
    C:\_scripts\xmltest.vbs(56, 3) Microsoft VBScript runtime error: Type mismatch:'cdate'
    THis is the Code:
    dfsDate = left(oneNode.text, Laenge)
    'nimm von links die 25 folgenden Zeichen (Friday, November 09, 2012)
    dfsVon = inStr(dfsDate, ",")
    'pruefe wo das 1. Komma ist und schreiben die Zeichen in die Variable
    dfsVon = dfsVon + 1
    wscript.echo dfsVon
    dfsBis = LEN(dfsDate)
    wscript.echo dfsBis
    dfsDate = mid(dfsDate, dfsVon, dfsBis)
    'Nimm die daten ab dem Komme bis zum Ende des Strings
    dfsDate = trim(dfsDate)
    'entferne die Leerzeichen Vor und Nach dem Sting
    Wscript.echo dfsDate
    dfsDate = cdate(dfsDate)
    'dfsDate = November 09, 2012 und wird in 09.11.2012 durch cdate umgebaut
    wscript.echo dfsDate
    I'm not sure why it is not working, could you help?
    Thanks & Regards
    Marius

  • Parsing xml with entity definitions inside it

    Hello All,
    I am trying to parse an xml file using DOM parser which has entities defined inside it for
    eg: <!ENTITY sample SYSTEM "sample_data" NDATA sample_ndata >
    and we are referring to the sample in some tag as value for attribute. When we try to parse the xml file its throwing saxexception
    org.xml.sax.SAXParseException: UndeclaredEntity: Entity 'sample' is not declared.
         at com.sun.org.apache.xerces.internal.jaxp.validation.Util.toSAXParseException(Unknown Source)
         at com.sun.org.apache.xerces.internal.jaxp.validation.ErrorHandlerAdaptor.error(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processOneAttribute(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processAttributes(Unknown Source)
    If anyone has faced same issue please help me in resolving the same. Appreciate any help.
    Thanks,
    Rakesh.

    Thanks DrClap !
    Not a problem. Here are the first lines of the file. Note the first node follows directly after the first line, which is the XML declaration:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <result status="ok">
    <stuff blah="omgwtflmao">
    ...etc
    Also, thanks for pointing out what you did. I should have noticed the first line in the JDOM FAQ that said "even if the validator is turned off".
    So... assuming my validator isn't turned off !?

  • Parsing xml with namespaces

    Hi
    I have to parse a xml file with 2 namespaces.
    The file looks like as follows
    <AA xmlns="http://XX.com/provider/C/D/E/F/2010/">
    <BB xmlns="">
    <Id>262</Id>
    <Time>2011-03-10T13:55:00.000-06:00</Time>
    <Indicator>true</Indicator>
    </BB>
    </AA>
    i tried following 3 methods to parse this xml file but failed
    PROCEDURE LOAD_XML
    IS
    l_clob := ' <<Above XML Content Here >>';
    lv_root CONSTANT VARCHAR2(1000) := '/AA/BB'; /* Tried lv_root CONSTANT VARCHAR2(1000) := 'AA/BB' with all the three methods */
    /* Method 1 */ lv_namespace constant varchar2(1000) := 'xmlns="http://XX.com/provider/C/D/E/F/2010/"';
    /* Method 2 */ lv_namespace constant varchar2(1000) := 'xmlns="http://XX.com/provider/C/D/E/F/2010/" xmlns=""';
    /*Method 3 */ lv_namespace constant varchar2(1000) := 'xmlns="http://XX.com/provider/C/D/E/F/2010/"/xmlns=""';
    BEGIN
    l_parser := dbms_xmlparser.newParser;
    BEGIN
    dbms_xmlparser.parseClob(l_parser, l_clob);
    END;
    l_doc := dbms_xmlparser.getDocument(l_parser);
    -- Free resources associated with the CLOB and Parser now they are no longer needed.
    dbms_xmlparser.freeParser(l_parser);
    l_nl := dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(l_doc),lv_root,lv_namespaces );
    FOR cur_rec IN 0 .. dbms_xmldom.getLength(l_nl) - 1 LOOP
    l_n := dbms_xmldom.item(l_nl, cur_rec);
    lv_rows_inserted_cnt := lv_rows_inserted_cnt + 1;
    dbms_output.put_line('I am Here');
    lv_rows_processed_cnt := lv_rows_inserted_cnt;
    dbms_xmldom.freeDocument(l_doc);
    l_clob := null;
    dbms_output.put_line(lv_rows_processed_cnt||' Rows Parsed ');
    END LOAD_XML ;
    Every time zero rows are being parsed and it's not going into the for loop at all.
    How to parse these kind of multiple namespaces (Especially default and unassigned namespaces ) ?
    Thanks
    Pramod

    As Anton showed, you don't need namespace if you directly access target node with the descendant axis.
    However, I guess it's a simplified example so if you need it in a more complex case, this will do it :
    DECLARE
    l_clob clob := '<AA xmlns="http://XX.com/provider/C/D/E/F/2010/">
    <BB xmlns="">
    <Id>262</Id>
    <Time>2011-03-10T13:55:00.000-06:00</Time>
    <Indicator>true</Indicator>
    </BB>
    </AA>';
    lv_root       CONSTANT VARCHAR2(1000) := '/ns1:AA/BB/*';
    lv_namespaces CONSTANT VARCHAR2(1000) := 'xmlns:ns1="http://XX.com/provider/C/D/E/F/2010/"';
    l_parser dbms_xmlparser.Parser := dbms_xmlparser.newParser;
    l_doc    dbms_xmldom.DOMDocument;
    l_nl     dbms_xmldom.DOMNodeList;
    l_n      dbms_xmldom.DOMNode;
    lv_rows_inserted_cnt  NUMBER := 0;
    lv_rows_processed_cnt NUMBER;
    BEGIN
    dbms_xmlparser.parseClob(l_parser, l_clob);
    l_doc := dbms_xmlparser.getDocument(l_parser);
    dbms_xmlparser.freeParser(l_parser);
    l_nl := dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(l_doc), lv_root, lv_namespaces);
    FOR cur_rec IN 0 .. dbms_xmldom.getLength(l_nl) - 1
    LOOP
       l_n := dbms_xmldom.item(l_nl, cur_rec);
       lv_rows_inserted_cnt := lv_rows_inserted_cnt + 1;
       dbms_output.put_line(dbms_xmldom.getNodeValue(dbms_xmldom.getFirstChild(l_n)));
    END LOOP;
    lv_rows_processed_cnt := lv_rows_inserted_cnt;
    dbms_xmldom.freeDocument(l_doc);
    dbms_output.put_line(lv_rows_processed_cnt||' Rows Parsed ');
    END;
    /If you're on version 10.2 (or +), maybe you'll find easier to use XMLTable instead :
    SQL> select *
      2  from xmltable(
      3    xmlnamespaces('http://XX.com/provider/C/D/E/F/2010/' as "ns1"),
      4    '/ns1:AA/BB'
      5    passing xmltype('<AA xmlns="http://XX.com/provider/C/D/E/F/2010/">
      6  <BB xmlns="">
      7  <Id>262</Id>
      8  <Time>2011-03-10T13:55:00.000-06:00</Time>
      9  <Indicator>true</Indicator>
    10  </BB>
    11  </AA>')
    12    columns id        number                   path 'Id',
    13            time      timestamp with time zone path 'Time',
    14            indicator varchar2(10)             path 'Indicator'
    15  )
    16  ;
            ID TIME                                              INDICATOR
           262 10/03/11 13:55:00,000000 -06:00                   true

  • Parsing XML with Namespace

    Hi,
    Can somebody help me with the following:-
    I have an XMLType in pl/sql as follows:
    <?xml version="1.0" encoding="utf-8"?>
    <rapdrpProcessCIN:GetCINRes xmlns:rapdrpProcessCIN="http://rapdrp.com/processcin/transactional/model/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://rapdrp.com/processcin/transactional/model/1.0/"
    xmlns:N1="http://rapdrp.com/common/bodcomponents/transactional/model/1.0/"
    xmlns:N2="http://rapdrp.com/gis/cin/business/model/1.0/">
    <rapdrpProcessCIN:ApplicationArea>
    <N1:Sender>
    <N1:Id>PRT01</N1:Id>
    </N1:Sender>
    <N1:Receiver>
    <N1:CompanyName>MGVCL</N1:CompanyName>
    <N1:CompanyId>string</N1:CompanyId>
    </N1:Receiver>
    <N1:Reference>
    <N1:BODCreationDateTime>1697-02-01T00:00:00Z</N1:BODCreationDateTime>
    <N1:BusinessProcessId>BP014</N1:BusinessProcessId>
    <N1:MessageId>string</N1:MessageId>
    <N1:TransactionId>string</N1:TransactionId>
    <N1:Username>string</N1:Username>
    <N1:Token>string</N1:Token>
    </N1:Reference>
    </rapdrpProcessCIN:ApplicationArea>
    <rapdrpProcessCIN:DataArea>
    <rapdrpProcessCIN:CIN>
    <N2:CIN>string</N2:CIN>
    </rapdrpProcessCIN:CIN>
    <rapdrpProcessCIN:ConsumerNumber>string</rapdrpProcessCIN:ConsumerNumber>
    <rapdrpProcessCIN:SRNumber>string</rapdrpProcessCIN:SRNumber>
    </rapdrpProcessCIN:DataArea>
    </rapdrpProcessCIN:GetCINRes>Note the xmlns attribute of the <message> tag is "" which is unusual, but not something I can't modify.
    I wish to extract the text string of the BusinessProcessId tag. I have attempted the following:
    DECLARE
    v_result varchar2(32765);
    v_xml XMLType;
    BEGIN
    v_xml := XMLType('....above XML....');
    v_result := xmltype.extract(v_xml, '/rapdrpProcessCIN:GetCINRes/rapdrpProcessCIN:ApplicationArea/Reference/BusinessProcessId/text()','xmlns:rapdrpProcessCIN="http://rapdrp.com/processcin/transactional/model/1.0/"').getStringVal();
    dbms_output.put_line('v_result:'||v_result);
    END;
    .... and I'm receiving the following result:
    ORA-30625: method dispatch on NULL SELF argument is disallowed
    ORA-06512: at line 6
    What am I doing wrong?
    Any help appreciated.
    Regards,
    Himani

    Hello,
    Can u please help me in resolving this issue.
    I need to parse an XML in which some tags does not contain data or there is no such tag present in an XML.
    Whenever i parse such a XML i receive error-ORA-30625: method dispatch on NULL SELF Argument is disallowed.
    As per my requirement - I may get values in all tags at one time and next time i may receive values of some fields only.
    I have tried this:
    DECLARE
    v_result varchar2(32765);
    v_xml XMLType;
    BEGIN
    v_xml := XMLType('<PurchaseOrder xmlns="http://rapdrp.com/processcin/transactional/model/1.0/">
    <Reference>SBELL-2002100912333601PDT</Reference>
    <Actions>
    <Action>
    <User>SVOLLMAN</User>
    </Action>
    </Actions>
    <Reject/>
    <Requestor>Sarah J. Bell</Requestor>
    <User>SBELL</User>
    <CostCenter>S30</CostCenter>
    <ShippingInstructions>
    <name></name>
    <address>400 Oracle Parkway
    Redwood Shores
    CA
    94065
    USA</address>
    <telephone>650 506 7400</telephone>
    </ShippingInstructions>
    <SpecialInstructions>Air Mail</SpecialInstructions>
    <LineItems>
    <LineItem ItemNumber="1">
    <Description>A Night to Remember</Description>
    <Part Id="715515009058" UnitPrice="39.95" Quantity="2"/>
    </LineItem>
    <LineItem ItemNumber="2">
    <Description>The Unbearable Lightness Of Being</Description>
    <Part Id="37429140222" UnitPrice="29.95" Quantity="2"/>
    </LineItem>
    <LineItem ItemNumber="3">
    <Description>Sisters</Description>
    <Part Id="715515011020" UnitPrice="29.95" Quantity="4"/>
    </LineItem>
    </LineItems>
    </PurchaseOrder>');
    v_result := xmltype.extract(v_xml,'/PurchaseOrder/ShippingInstructions/name/text()','xmlns="http://rapdrp.com/processcin/transactional/model/1.0/"').getStringVal();
    dbms_output.put_line('v_result:'||v_result);
    END;
    In this the value in <name></name> tag is NULL.
    Please let me know if i can parse this XML.
    Regards,
    Himani

  • Parsing XML with Java - seeking advice for method to pursue

    Hi guys
    So here's the deal: I want to parse some XML from a server, get all the data I need from it, then shunt that data to the classes that need it. However, I'm really not sure what the best way of parsing the XML is.
    I've just written a class for obtaining the file, and one for building a DOM from the XML file. But looking at org.w3c.dom in the Java API documentation (see HERE) I'll have to implement shedloads of interfaces to be able to take advantage of the DOM, and I don't even know a lot about it.
    So am I best just writing a simple parser based on regular expressions to get the data I want? There's about 5 attributes in the XML file that I need to get - 5 for each instance of the containing element. So I don't think it'll be hard to do with regular expressions.. plus even if I did decide to implement all the DOM interfaces, the only way I'd know how to do half the stuff is with regular expressions anyway. I mean, how else would you do it? How else could you match up Nodes according to the Strings you're using for the elements, attributes etc?
    I worry that a parser using regular expressions might be too slow... I'm building this as an applet to visually display information from the server. I have nothing to support those fears, I'm just not experienced enough to know whether speed would be a problem if I chose this route... I don't think it would, but really need confirmation of that suspicion being unfounded.
    Any advice would be very, very welcome, as I'm tearing my hair out at the moment, unsure what to do.

    Komodo wrote:But JDOM is not in the core class libraries, is it? So if I want to create an applet embedded into a website, am I able to get people to download that as well?
    Sorry, I don't know anything about applets.
    Komodo wrote:Everyone's advice is appreciated, but my core question remains unanswered - would using regular expressions, considering how simple and unchanging the XML files are, be a viable option in terms of speed?
    Yes! I've done more than my fair share of XML processing with REs. It's not always easy. I often wish I could just use something XPath-like. But it's certainly easy to do and would probably mean that you'd have something up and running quicker than if you spent time investigating pure XML parsing approaches.

Maybe you are looking for

  • Photoshop CS6 "failed to initialize" error...

    hi, everyone. i tried to install photoshop CS6 but i got "failed to initialize" error message. i tried everything in the web site http://forums.adobe.com/message/2786497#2786497 but it didn't work out. i uninstalled all adobe product with appcleaner

  • Down payments routed through SD

    Dear All:              As per management requirment we want to route our down payments from customer in the form of advances through SD. As an FI key user i am only aware of FI settings to be done in my area. Since SD consultant is absent so in his a

  • How to show the VALUE as the Column Header using SQL query?

    Hi I have a requirement to show the picked value as the column header using SQL query. Example: ====== SELECT EMPNO FROM EMP WHERE EMPNO=7934; Result Should be: 7934 7934

  • Problem Transporting Web Forms

    Hi Experts, I have been trying to export the custom web forms from POC server to Dev server. But then i'm not able to find the web form in the target server.. For exporting i followed this method.. Content Administration  KM Content  Export  Pendi

  • I have to restart ipad each time for internet access.  Why?

    I have to restart ipad each time for internet access and some games.  Never happened until about 2 weeks ago.  ?