Can't parse a XML file

Hello,
I'm using OracleJSP + XML Parser v2 Java.
I've got the following XML:
<ongletmenu>
<onglet>
<name>Proprietes</name>
<link>proprietes.jsp</link>
</onglet>
<onglet>
<name>Personnes</name>
<link>personnes.jsp</link>
</onglet>
<onglet>
<name>Formations prorposees</name>
<link>formations.jsp</link>
</onglet>
</ongletmenu>
And I want to parse this file with a JSP file:
<%@ page import="java.io.*" %>
<%@ page import="java.net.*" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="org.xml.sax.*" %>
<%@ page import="arfopa.XSLT" %>
<%
String retour="";
DOMParser parser = new DOMParser();;
XMLDocument theXMLDoc;
parser.setPreserveWhitespace(true);
parser.setValidationMode(true);
parser.showWarnings(true);
try { parser.parse("onglets_organismes.xml"); }
catch (SAXParseException s) { out.println(s.getMessage()); }
theXMLDoc = parser.getDocument();
NodeList nl = XSLT.select(theXMLDoc, "//onglet");
// Print Out the Names of the Matching Items
int matches = nl.getLength();
for (int i = 0; i < matches; i++ ) {
retour += XSLT.valueOf( nl.item(i), "name");
%>
<%=retour%>
The JSP file doesn't want to parse the file
(parser.parse). Any idea?
Nicolas
null

Problem is that the string you pass the parse() method must be a valid string representation of a URL.
The string "onglets_organismes.xml" isn't.

Similar Messages

  • Can I parse an XML file as a StringBuffer?

    I have an XML file loaded into a StringBuffer and would like to parse it as:
    (parser is a DOMParser object)
    parser.parse(aXMLStringBuffer.toString());
    I'm getting the data from a PL/SQL Stored Procedure - is there an alternative method for passing the to this function?
    Thanks,
    Andy Shiels

    Hi Andy...
    I JUST finished a Proof of Concept servlet, that makes use of an XML file loaded from a file as a string. I used StringReader, as opposed to StringBuffer.
    Hope this helps...
    Will.
    CODE SNIPPET:
    parser.parse(new StringReader(xmlString));
    XMLDocument xmlDocument = parser.getDocument();
    ...

  • Can someone help me with a problem of parsing an XML file?

    Hello,
    I'm having some problems parsing an xml file. I get a SAXNotSupportedException when setting a property value.
    Here is the piece of code where I have the problem:
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    SAXParser saxParser = spf.newSAXParser();
    XMLReader xmlReader = saxParser.getXMLReader();
    DefaultHandler defHandler = new DefaultHandler();
    xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", defHandler);
    and the log is:
    Problem with the parser org.xml.sax.SAXNotSupportedException: PAR012 For propertyID "http://xml.org/sax/properties/lexical-handler", the value "org.xml.sax.helpers.DefaultHandler@4ff4f74a" cannot be cast to LexicalHandler.
    http://xml.org/sax/properties/lexical-handler org.xml.sax.helpers.DefaultHandler@4ff4f74a LexicalHandler
    I've been working on this problem but I can't find the error.
    Does anyone have an idea of what to do to solve it?
    Thanx in advance,
    M@G

    before deciding which XML technology to use, you should see if your application fit in the category below:
    use SAX:
    1. The XML file is rather large (30 or 40+ MB)
    2. I don't need the xml document in memory. I will parse the document and store the data in my own object.
    use DOM or JDOM
    1. The XML file is relatively small (less than 30 MB) or I can increase the runtime memory for larger xml file.
    2. I will need to walk up and down the xml document tree severals time.
    3. My application is in Java and it's not going to be rewritten in C++, etc (use JDOM)
    NOTE:
    JDOM is rather easier to use (for Java developer), but it's not an www.org.com standardlized xml parser.
    personally, i like JDOM for traversing the DOM.

  • Can Document Builder parse an XML file from a URL?

    Warning: Java newbie here...
    My problem is that I am able to parse an XML file if it is copied into my project, but not if it is a full URL. Here is what I got so far, that works.
    import java.io.*;
    import java.net.*;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    try {
        File file = new File("path/to/file.xml");
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(file);
        doc.getDocumentElement().normalize();
        NodeList nodeLst = doc.getElementsByTagName("Names");
        for (int s = 0; s < nodeLst.getLength(); s++) {
            Node parentNode = nodeLst.item(s);
            if (parentNode.getNodeType() == Node.ELEMENT_NODE) {
                Element parentElmnt = (Element) parentNode;
                NodeList nameElmntLst = parentElmnt.getElementsByTagName("Name");
                //etc.
    } catch (Exception e){
        e.printStackTrace();
    }So building off of this I have tried to parse an input stream like this:
    URL url = new URL("http://example.com/file.xml");
    InputStream is = url.getInputStream();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(is);which gives me the following error
    [Fatal Error] :-1:-1: Premature end of file.
    LOG: HME receiver connected
    org.xml.sax.SAXParseException: Premature end of file.
    I also even tried to write the file locally like this:
    URL url = new URL("http://example.com/file.xml");
    HttpURLConnection urlcon = (HttpURLConnection) url.openConnection();
    urlcon.connect();
    InputStream is = urlcon.getInputStream();
    File file = new File("path/to/file.xml");
    OutputStream out = new FileOutputStream(file);
    byte buf[] = new byte[1024];
    int len;
    while((len=is.read(buf))>0)
        out.write(buf,0,len);
    out.close();
    is.close();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(file);This gives the same error.
    If anyone can point me in the right direction I would forever thankful. I've tried search Google and the Sun forums, but haven't quite found the solution. I think it is because I need to try something else completely. Thank you for reading.
    ~~~~ Jeremy

    jmose wrote:
    If I copy the page, it works as shown in the first code block. In the third codeblock the file is never even created, so I cannot tell if that works or not.So: having the parser access the URL fails, and having some other Java code access the URL also fails in the identical way? That suggests the problem is simply accessing the URL via Java code. Presumably when you downloaded the data from the URL, you used a browser to do it and not wget or something like that?

  • How different Web Services can use a class which parses an XML file

    I am using RAD6.1 for developing and deploying web services.As I am using 15 web Services which uses a common class which is used to parse an XML file.As this XML file should be parsed only once and should be used by all the web services.I have made this common class as Singleton but it works as singleton for only one webservice and for other web service again it is parsing the xml file.I want to parse this xml file only once and used by all the web services.In my case tis file is parsed 15 times for 15 web services, but it should be parse donly once and used by all 15 services.Please give me the solution.
    Thanks and Regards
    Sayeeduzzaman

    Hello,
    the 15 Webservices should have a static attribute which contains the xml:
    private static String xml;
    then initialise the xml like this:
    if (xml == null)
    xml = parseIt();
    else
    //do nothing, XML already initialised!
    }

  • Parsing of xml file in oracle stored procedure on linux server

    We have an XML file in the "/database/stats/dev/xml1/" path and tried to parse the file using the below code :
    p := xmlparser.newParser;
    xmlparser.setValidationMode(p, FALSE);
    -- xmlparser.setErrorLog(p, errfile);
    xmlparser.setBaseDir(p, dir);
    xmlparser.parse(p, inpfile);
    doc := xmlparser.getDocument(p);
    xmlparser.freeParser(p);
    The above procedure is throwing below mentioned exception at "xmlparser.parse(p, inpfile);".
    SQLCODE: ORA-31001
    SQLERRM: ORA-31001: Invalid resource handle or path name "/xml1.dtd"
    The xml file contains the following line, which is giving an error, while parsing the xml file.
    <!DOCTYPE CCIOrder SYSTEM "xml1.dtd">
    Directory Structure:
    OWNER DIRECTORY_NAME DIRECTORY_PATH
    SYS XML1 /database/stats/dev/xml1

    you'll need to use server-side code to check the xml file names in that folder, return that list to flash and display the list to the user.
    or, if you can get by presenting a hard-coded list of xml files, you won't need any server-side coding.

  • Parsing an XML file

    I've written a program which is partly responsible for parsing an XML file that can be found on the web. I appear to be accessing the XML file correctly, but when I try to parse it I am running into a problem. I try to create a List object that contains all of the children of the root element. The code looks like this:
    Document doc = parser.build(xmlFile);
    Element root = doc.getRootElement();
    List rootChildren = root.getChildren();But I get an error that say that "the type List is ambiguous". I am importing java.util.*. I am trying to do this exactly like a few examples I found on the web, but I can't seem to get past this issue. What do I need to keep Eclipse from telling me that List is not an ambiguous type.

    Maybe you haveimport java.util.*;
    import java.awt.*;Both packages contains a List class.
    In that case, the compiler doesn't know which one you're talking about.
    If you don't need the java.awt.List class here, try not to import it.
    If you need it, use the fully qualified class name in your code.

  • Parse exisitng xml file and recreate another xml file with different struct

    Is it possible in java using dom parser to parse an exisiting xml file and recreate a new xml file from data obtained by parsing old xml file.
    I checked on old forum threads and everywhere either parsing xml file has been explained or creating new xml file from scratch has been shown.
    Any examples/guidance will be appreciated....

    The general process is:
    Document dom1 = ... // the parsed document
    Document dom2 = ... // new document constructed on the fly
    Node nD1 = ... // some random node found in dom1
    // copy the node from dom1 and associate with dom2
    Node nD2 = dom2.importNode(nD1, true);
    // ... treat nD2 as a node which can now be inserted into dom2 ...
    Node otherD2 =  ... // some other node already in dom2
    otherD2.appendChild(nD2);Note, in this example the nD1 node is copied (including any sub-nodes) into a new node, nD2. You can alternately move the node from one Document to another using Document.adoptNode(), however this may fail (see the javadoc).

  • How to parse a XML file

    I am a new learner to XML & JAVA,I dont't know how to parse the XML file using JAXP,Who can tell me,Who can write an Example?
    thx
    Best Regards.

    Using the SAXParser in JAXP the parsing of the XML file is event driven.
    Instantiate the parser:
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser parser = factory.newSAXParser();
    InputSource is = new InputSource(new FileReader(theXML));call the parse method:
    parser.parse(is, this);The following events are fired as the parser works through the XML public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws org.xml.sax.SAXException
    public void endElement(String namespaceURI, String localName, String qName) throws org.xml.sax.SAXException
    characters(char[] ch, int start, int length)etc.
    You write what you want within each of these sections to handle the structure of your data. Keep in mind SAX is useful only when you know the structure of your XML.

  • Error "Cannot parse appinfo xml file."

    Periodically my users are getting the error below when trying to launch BPC for Excel:
    "Cannot parse appinfo xml file."
    Seems this file is getting corrupted somehow. If I remove the file from their citrix profile and they relogin, the file is recreated and then they can launch BPC for Excel. Until then though, they get this error and sometimes it says the Web App server is unavailable, when it indeed is available.
    Anyone experience this, or have any ideas as to the problem?
    Thanks,
    Greg

    Please notice that inquiries related to BPC topics should now be posted to dedicated forums.
    Business Planning and Consolidations, version for SAP NetWeaver
    <a class="jive_macro jive_macro_community" href="" __jive_macro_name="community" modifiedtitle="true" __default_attr="2065"></a>
    Business Planning and Consolidations, version for the Microsoft Platform
    <a class="jive_macro jive_macro_community" href="" __jive_macro_name="community" modifiedtitle="true" __default_attr="2066"></a>
    Please adjust any bookmarks or shortcuts you may have set previously to point to this forum.
    Best regards,
    [Jeffrey Holdeman|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/profile/jeffrey+holdeman]
    SAP BusinessObjects
    Enterprise Performance Management
    Regional Implementation Group

  • Want parse huge xml file for CDATA

    HI all
    I want to parse hude xml file for getting values of CDATA
    can u plz give me sample code for that
    here i am attaching the part of my xml file
    <initParams>
    <param description="simulation mode " name="smtpSimulationMode" passOn="false" required="false" type="bool" varSubstitute="false">
    <![CDATA[false]]>
    </param>
    <param description="full name of smtp host" name="smtpHost" passOn="false" required="true" type="string" varSubstitute="false">
    <![CDATA[222222]]>
    </param>
    <param description="smtpUserName for authentication" name="smtpUserName" passOn="false" required="false" type="string" varSubstitute="false"/>
    <param description="smtpUserPassword for authentication" name="smtpUserPassword" passOn="false" required="false" type="string" varSubstitute="false"/>
    <param description="ip address for remote server" name="serverId" passOn="false" required="true" type="string" varSubstitute="false">
    <![CDATA[1111111]]>
    </param>
    <param description="location of file on remote server side" name="fileRemoteLocation" passOn="false" required="false" type="string" varSubstitute="false">
    <![CDATA[test/]]>
    </param>
    <param description="user name for authentication" name="userName" passOn="false" required="true" type="string" varSubstitute="false">
    <![CDATA[abc]]>
    </param>
    </initParams>
    thanks in advance

    There are several Java XML API's available. SAX, JXpath, DOM4J, Xerces, etcetera.

  • Altering a DOM once it has been created after parseing an XML file

    Does anyone know of a nice easy way to edit a DOM once I have parsed it in so that I can write an altered XML file back to disk. (I can do the reading and writing easy enough, I just need the editing part.
    I used to have code that worked if the child node you altered was directly off the root but I need something a bit more genric so that I can say:
    replace(Document doc, String tag, String sub_tag, String item);
    Where doc is the current DOM, tag is the main tag (not always the root), sub_tag is the specific tag I want to alter and item is the value I want to set the sub_tag to.
    i.e. I want to read in XML like
    <root>
    <name>aname</name>
    <blob>ablob</blob>
    <sub>
    <name>subname</name>
    <item>anitem</item>
    </sub>
    </root>
    and have one method where I can change the root name or the sub name.
    Any ideas ?

    FYI here is how I did it in the end.
    * Finds where the child tag we are looking for occurs and then replaces it with
    * the a modified clone of the child.
    * @param doc The Document to alter.
    * @param parent_tag The tag to alter.
    * @param child_tag The sub_tag that will be altered.
    * @param item The item to insert as the value of a tag.
    * @param index_one The index of the parent tag incase there is more than one.
    * @param index_two The index of the child tag incase there is more than one.
    * @return The modified document.
    private Document putItemInDoc(Document doc, String parent_tag, String child_tag, String item, int index_one, int index_two)
    Document tempDoc = doc;
    Element root = tempDoc.getDocumentElement();
    boolean found = false;
    Node parent = null;
    NodeList matches = tempDoc.getElementsByTagName(parent_tag);
    //get the parent node we know the child to be on.
    parent = matches.item(index_one);
    NodeList childList = parent.getChildNodes();
    int count = 0;
    int i = 0;
    do{
    if((childList.item(i)).getNodeName().equals(child_tag))
    if(count==index_two)
    Node child = childList.item(i);
    Node clone = child.cloneNode(true);
    clone.getFirstChild().setNodeValue(item);
    found = true;
    System.out.println("found");
    //replace child node with modified clone.
    tempDoc.getElementsByTagName(parent_tag).item(index_one).replaceChild(clone,child);
    else
    count++;
    i++;
    }while((i<childList.getLength())&&(!found));
    return(tempDoc);

  • Opatch error 'Unable to parse the xml file'

    Hi there,
    I am new to installing patches on Oarcle and I need to install patch 12375678 on my windows system, Oracle 11.2.0.2.
    I have followed the instructions in the readme.txt file, but got this error and I have not come across anywhere on the web that explain how I could fix it.
    Could you please advise?
    Thanks
    C:\>set oracle_home=C:\oracle\product\11.2.0\dbhome_1
    C:\>echo %oracle_home%
    C:\oracle\product\11.2.0\dbhome_1
    C:\>cd C:\oracle\product\11.2.0\dbhome_1\inventory\oneoffs\12375678
    C:\oracle\product\11.2.0\dbhome_1\inventory\oneoffs\12375678>opatch apply
    Invoking OPatch 11.2.0.1.1
    Oracle Interim Patch Installer version 11.2.0.1.1
    Copyright (c) 2009, Oracle Corporation. All rights reserved.
    Oracle Home : C:\oracle\product\11.2.0\dbhome_1
    Central Inventory : C:\Program Files\Oracle\Inventory
    from : n/a
    OPatch version : 11.2.0.1.1
    OUI version : 11.2.0.2.0
    OUI location : C:\oracle\product\11.2.0\dbhome_1\oui
    Log file location : C:\oracle\product\11.2.0\dbhome_1\cfgtoollogs\opatch\opatch2
    012-05-21_15-28-52PM.log
    Patch history file: C:\oracle\product\11.2.0\dbhome_1\cfgtoollogs\opatch\opatch_
    history.txt
    ApplySession applying interim patch '12375678' to OH 'C:\oracle\product\11.2.0\d
    bhome_1'
    Running prerequisite checks...
    OPatch detected non-cluster Oracle Home from the inventory and will patch the lo
    cal system only.
    Backing up files and inventory (not for auto-rollback) for the Oracle Home
    Backing up files affected by the patch '12375678' for restore. This might take a
    while...
    Backing up files affected by the patch '12375678' for rollback. This might take
    a while...
    Patching component oracle.rdbms, 11.2.0.2.0...
    Copying file to "C:\oracle\product\11.2.0\dbhome_1\rdbms\xml\xsl\kuexttbl.xsl"
    Patching component oracle.rdbms.dbscripts, 11.2.0.2.0...
    Copying file to "C:\oracle\product\11.2.0\dbhome_1\rdbms\admin\prvtbpd.plb"
    Copying file to "C:\oracle\product\11.2.0\dbhome_1\rdbms\admin\prvtbpw.plb"
    ApplySession adding interim patch '12375678' to inventory
    Interim Patch metadata parsing failure... 'Unable to parse the xml file.'
    ApplySession failed: ApplySession failed in system modification phase... 'Unable
    to create patchObject'
    OPatch will attempt to restore the system...
    Restoring the Oracle Home...
    OPatch was able to restore your system. Look at log file and timestamp of each f
    ile to make sure your system is in the state prior to applying the patch.
    OPatch failed with error code = 73

    your actions.xml must not be able to be read.
    open it in notepad yourself to see does it open, if so its not corrupt, if doesnt open download patch again.
    More then likely will be fine so try locate the patch in a shorter home path, like c:\patches\12375678 and see does it install from there.
    Only other thing I can think of is the main inventory.xml, usually c:\program files\oracle\inventory\inventory.xml
    try notepad with that too.

  • How to parse large xml file

    I need to parse large xml file which contains following tag. The size of the file is upto 10MB-50MB or more.
    <departments>
    <department>
    <a_depart id="124">
    <b_depart id="Bss_253">
    <bss_depart id="253">
    <attributes>
    <name_one>abc</name_one>
    </attributes>
    </bss_depart id="253">
    </b_depart id="Bss_253">
    </a_depart id="124">
    </department>
    <department>
    <a_depart id="124">
    <b_depart id="Bss_254">
    <mss_depart id="253">
              <attributes>
              <name_one>abc</name_one>
              <name_two>xyz</name_one>
              </attributes>
         </mss_depart>
         </b_depart>
    </a_depart>
    </department>
    <department>
    <a_depart id="124">
    <b_depart id="Bss_254">
    <mss_depart id="255">
              <attributes>
              <name_one>abc</name_one>
              <name_two>xyz</name_one>
              </attributes>
         </mss_depart>
         </b_depart>
    </a_depart>
    </department>
    <department>
    <a_depart id="125">
    <b_depart id="Bss_254">
    <mss_depart id="253">
              <attributes>
              <name_one>abc</name_one>
              <name_two>xyz</name_one>
              </attributes>
         </mss_depart>
         </b_depart>
    </a_depart>
    </department>
    I want to get the infomation for that xml file. like mss_depart id=233, building xpath dyanmically for every id and loading
    that using dom4j. which is very very slow.
    Is there any other solution for that to read the data using sax parser only.
    I want to execute the xpath or data for the following way.
    //a_depart/@id ------> all the ids of a_depart tags if it returns 3 values say 123,124,125
    after that i want to execute
    //a_depart[@id='123']/b_depart/@id like this ...to retrive the values of all the levels ...
         I am executing following xpath for every unique ids at all levels.
         List l = doc.selectNodes(xPathForID);
         List l1 = doc.selectNodes(xPathForAttributes+attributes.get(j)+"/text()");
    But it is very slow and taking lot of time.
    Is there any other way to solve this problem. If any please mail me it is urgent.
    I am using jdk1.4 and jdk1.5
    Is there any support for sax parser to execute xpath in jdk1.5 direclty, with out using dom4j
    Thanks in advance....

    I doubt you will find a preexisting solution to your problem.
    SAX is usually recommended for processing big files (where "big" is undefined"). It works on big files by avoiding the messy problem of storing the data -- that is left as an exercise to you.
    DOM (and its variants) works by building a Document object as the head of the tree of objects for the entire contents. With DOM, you can then use XPath, because there is something to search that is already in memory. To use XPath, you seem to have two choices, build a DOM-ish tree, or if you can find an XPath processor (I'm not sure if one exists) that can process the XML file directly, but it will be slow, since you are looking for "all" occurences of an attribute, and this means you have to read the entire file each time.
    It might be worth exploring a hybrid approach -- use SAX to get some information, and build your own objects to store the data. Maybe a HashMap as the main index. But, that will keep you from using XPath, since you do not have the data structures it expects.
    A third alternative would be to look at JAXB. It builds Java code from a Schema of your data and then when you import the data, it creates the necessary objects and fills in values. But, I don't think XPath woll work there either.
    Dave Patterson

  • Problem with parsing large xml files

    Hello All,
    I am parsing a large xml file of 20MB and I use DocumentBuilder.parse(File). This method works for small xml files with size less than 20MB but the application hangs and doesn't through any error message when parsing 20MB xml files. Please let me know what I have to do at this point ?
    Thanks & Regards,
    Kumar.

    Well... i can't agree.
    If you have such structure:
    <task>
      <task/>
      <task>
         <task>
            <task/>
         </task>
         <task/>
      </task>
    </task>
    ...you may always keep stack of tasks (at startElement push to top, and at endElement pop), so at every leaf of tree you will have all parents of that leaf.
    for such structure:
    <task id="1" parent="0"/>
    <task id="2" parent="1"/>
    <task id="3" parent="1"/>
    <task id="4" parent="2"/>
    <task id="5" parent="3"/>
    ...it will be much faster to go thro document by sax several times to build tree of tasks, than to load all document into memory...

Maybe you are looking for