How to read the attribute of the xml file using jaxb

Thanks,
Buddy as i have a issue i have to read the xml file using jaxb and xml file contains this data and i have read the attribute like name , desc and action for a particular menu name pls tell the code how to do this it will be a great favour to me
thanx in advance
Rasool
<contextmenu>
<menu name='Lead' >
<menuitem name='newlead' desc='New Lead' action='/leads.do?dispatch=insert' />
<menuitem name='editlead' desc='Edit Lead' action='' />
<menuitem name='leadinfo' desc='Lead Information' action='' />
</menu>
<menu name='Cases' >
<menuitem name='' desc='' action='' />
<menuitem name='' desc='' action='' />
<menuitem name='' desc='' action='' />
</menu>
<menu name='Contact' >
<menuitem name='' desc='' action='' />
<menuitem name='' desc='' action='' />
<menuitem name='' desc='' action='' />
</menu>
</contextmenu>

What my program do is to get the encoding of XML files and convert them to UTF-8 encoding files, while I need this "encoding" information of the original XML document thus I can convert...
After reading specifications and JDOM docs, the truth turns to be disappointed, no function is provided to get this information in JDOM level 2(the current released one), while it's promissed that this function will be provided in JDOM level API....
Thanx all for your help and attention!!!

Similar Messages

  • How to change the attributes of an XML file

    hi peeps 'ope you can help me here i need to change the attributes of an xml file, i parse it first using a DOM parser but i cant find a way to change the attributes in the XML file, setAttribute() works only at runtime and doesn't change the attribute in the file itself. I can't find a method that will answer my question. I've searched through the forum and found similar threads....they say in order to write and change the attribute i must use the write() method of the XmlDocument class defined in com.sun.xml.tree.XmlDocument. But, i found another thread, and it says that com.sun.xml.tree.XmlDocument is not safe to use and i should use org.apache.crimson.tree.XmlDocument.....i can't find the XmlDocument class and the API for this package so i really dont know where to start...hope you guys can help me! thnx

    thanks for responding roland....i already found the solution...i didn't use the XmlDocument class because i can't find any documents about it except for JAXP 1.0 here is my code snippet...i used the TransformerFactory and Transformer class to write
    import org.w3c.dom.*;
    import org.w3c.dom.traversal.*;
    import javax.xml.parsers.*;
    import javax.xml.transform.*;
    import javax.xml.transform.dom.*;
    import javax.xml.transform.stream.*;
    Document doc = null;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    dbf.setValidating(false);
    doc = db.parse(fileGetFile); //this is the XML file
    n1 = (Node)doc.getDocumentElement();
    e1 = (Element) n1;
    NodeList nodeList = doc.getElementsByTagName ("File");
    //just insert whatever you want to do with the XML...parse it..set/change the attribute..etc....sample snippet below changes the attribute downloaded to "no"
    for(int iWriteFailed = 0; iWriteFailed <nodeList.getLength() ; iWriteFailed ++){     
    n2 = nodeList.item(iWriteFailed);
    e2 = (Element) n2;          
    e2.setAttribute("downloaded", "no");}
    try{
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(new DOMSource(doc), new StreamResult ( new FileOutputStream ( fileGetFile) ) );}
    catch(Exception trans){}
    thanks for responding and keeping the information interchange alive here in the forum...
    Pau

  • How to read an attribute of an xml tag in jsp.

    hi guys,
    This is murali krishna. i have a small problem,
    i have one xml file (books.xml)
    <?xml version="1.0" encoding="iso-8859-1"?>
    <library>
    <book id="1">
    <name>Head First Java, 2nd Edition</name>
    <author>Kathy Sierra and Bert Bates</author>
    <publication-date>09-Feb-2005</publication-date>
    </book>
    <book id="2">
    <name>Effective Java</name>
    <author>Joshua Bloch</author>
    <publication-date>28-May-2008</publication-date>
    </book>
    <book id="3">
    <name>Java How to Program, 7th Edition</name>
    <author>Harvey M. Deitel and Paul J. Deitel</author>
    <publication-date>6-Jan-2007</publication-date>
    </book>
    </library>
    I tried to read this xml file in jsp as shown below
    <%@ page language="java" %>
    <%@ page import="org.w3c.dom.*" %>
    <%@ page import="javax.xml.parsers.DocumentBuilder" %>
    <%@ page import="javax.xml.parsers.DocumentBuilderFactory" %>
    <%
    DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
    DocumentBuilder db =dbf.newDocumentBuilder();
    Document doc=db.parse("c:\\books.xml");
    NodeList nl = doc.getElementsByTagName("book");
    %>
    <html>
    <head>
    <title>How to read XML file in JAVA</title>
    </head>
    <body>
    <%
    for(int i=0;i<nl.getLength();i++)
    NodeList nameNlc= doc.getElementsByTagName("name");
    Element nameElements=(Element)nameNlc.item(i);
    String nameTagValue=nameElements.getChildNodes().item(0).getNodeValue();
    NodeList authorNlc= doc.getElementsByTagName("author");
    Element authorElements=(Element)authorNlc.item(i);
    String authorTagValue=authorElements.getChildNodes().item(0).getNodeValue();
    NodeList dateNlc= doc.getElementsByTagName("publication-date");
    Element dateElements=(Element)dateNlc.item(i);
    String dateTagValue=dateElements.getChildNodes().item(0).getNodeValue();
    out.println("name :"+nameTagValue+"<br>");
    out.println("author :"+authorTagValue+"<br>");
    out.println("publication-date :"+dateTagValue+"<br><br>");
    %>
    </body>
    </html>
    so, my problem is I was unable to read the attribute of the tag book , that is "id".
    can any one tell me how to read this "id" attribute.
    Murali Krishna
    [email protected]

    hi,
    U r retriving the elements by tag name.So it just chks the tag name ie.<book> & gives u array of elements.But u need retrive d attribute of <book> tag itself.
    =Solution =====
    Add one more statement ----> var[]= doc.getElementsByName("book");
    Now u hav book elements as an array & can retrive id in for loop
    for(var; var.length;var++)
    doc.element[var].id.value

  • How to read configuration data from an xml file (not web.xml)?

    Hi,
    I want to separate the application specific configuration parameters in a separate xml file and read them as and when they are needed? I know that I can use the wb.xml but I want to separate them in a different xml file because I don't want the web.xml file to be played around later after deployment. If any change is needed then it should be done in the application-config.xml.
    How can I read the parameters from this xml file in my jsp code and also what should be the location of this file if I have
    ../webapps/Root/application
    directoty structure ?
    Any help is greatly appreciated.

    can you give an example of a property file and also
    it is loaded in the jsp ?Hmm... loading properties in a JSP is not a very good idea. You should do it in a separate class, rather than mixing the logic with the display logic.
    Properties properties = new Properties();
    properties.load(UtilClass.class.getResourceAsStream("config.properties"));
    // Add a try - catch block around the load
    // for IOException...

  • How to read XMP metadata of an indd file using Actionscript

    Hi All,
    I am trying to read XMP metadata of an indd file using CS Extension Builder in Flash Builder 4.5.
    The documentation has many class like XMPmeta, XMPStruct, etc.
    I have got the currently opened document in InDesign as follows:
    var myDoc:Document = InDesign.app.activeDocument();
    And a new XMPmeta object is created as follows:
    var myXMP:XMPMeta = new XMPMeta();
    How to initialize document's xmp metadata in the XMPMeta object? Or is there any other way to get the XMP metadata of currently opened document in InDesign?

    I have found that the XMP data of an InDesign document can be retrieved in actionscript as follows:
    InDesign.app.activeDocument.metadataPreferences
    This returns the MetadataPreference object.
    But I am not able to iterate each namespace in the xmp. There isn't any XMPFile class which allows me to serialize the object to xml file so that I can iterate all elements in the XMP.
    I could not relate class like XMPMeta, XMPProp, etc. with the MetaDataPreference class. So, how to obtain the entire xmp packet from the MetadataPreference object?
    Can anyone shed light on this?

  • How to read a table from a word file, using HWPF

    How can I read a table from a Word file using HWPF?
    I looked in API and Table class doesn't seem to have a constructor... very very strange for me. pls help

    the constructor is HWPFDocument = new HWPFDocument(/*file*/)
    Here is the API for that
    http://poi.apache.org/apidocs/org/apache/poi/hwpf/HWPFDocument.html
    Also here is another link to something that might help you more with tables
    http://www.aspose.com/Community/forums/thread/79182.aspx

  • How to get the "encoding" of a XML file using JDOM

    As in XML file, <?xml version="1.0" encoding="UTF-8" ?> indicates the encoding of this file
    while using JDOM to parse a XML file, how can I get the encoding type?
    thanx!!!

    What my program do is to get the encoding of XML files and convert them to UTF-8 encoding files, while I need this "encoding" information of the original XML document thus I can convert...
    After reading specifications and JDOM docs, the truth turns to be disappointed, no function is provided to get this information in JDOM level 2(the current released one), while it's promissed that this function will be provided in JDOM level API....
    Thanx all for your help and attention!!!

  • How to delete a perticular node from xml file using java code

    Hii All,
    Now i am trying to delete a perticular node from xml file.Like...
    XML file:
    <Licence>
    <SERVER>
    <was id="1">1</was>
    <was id="2">2</was>
    </SERVER>
    </LICENCE>
    I am working in messaging service using JABBER framework with whiteboard facility.
    Here Some commands i have created to add,modify,delete nodes from xml file.They Are
    1.If u want to add a new node then.
    create Licence.SERVER <ss id="3">ddd</ss> lic.xml
    (here u want to add a new node called "ss" under Licence.SERVER.
    And lic.xml is tyhe xml file name where it was saved.
    2.If u want to delete a node(Suppose <was id="1">),then the command should be
    delete Licence.SERVER.was:id='"1" lic.xml
    A problem arises that here it find two was attributes.And it delete the last was attribute,not the requested node.
    PLEASE HELP ME IN SOLVING THIS CODE..
    ------------------------------------

    Looks like you clicked on "Post" before you pasted in the code you were talking about.

  • How to read some lines from a text file using java.

    hi,
    i m new to java and i want to read some lines from a text file based on some string occurrence in the file. This file to be read in steps.
    we only want to read the file upto the first Occurrence of "TEXT" string.
    How to do it ,,,
    Kinldy give the code
    Regards,
    Sagar
    this is the text file
    dfgjdjj
    sfjhjkd
    ghjkdg
    hjkdgh TEXT
    ikeyt
    ujt
    jk
    tyk TEXT
    rukl
    r

    Hendawy wrote:
    Since the word "TEXT" is formed of 4 letters, you would read the text file 4 bytes by four bytes. Wrong on two counts. First, the file may not be encoded 1 byte per character. It could be utf-16 in which case it would be two byte per character. Second, even if it were 1 byte per character, the string "Text" may not start on a 4 byte boundary.
    Consider a FileInputStream object "fis" that points to your text file. use fis.read(byte[] array, int offset, int len) to read every four bytes. Convert the "TEXT" String into a byte array "TEXT".getBytes(), and yous the Arrays class to compare the equality of the read bytes with your "TEXT".getBytes()Wrong since it relies on my second point and will fail when fis.read(byte[] array, int offset, int len) does not read 4 bytes (as is no guaranteed to). Check the Javadoc. Also, the file may not be encoded with the default character encoding.
    The problem is easily solved by reading a line at a time using a BufferedReader wrapping an InputStreamReader wrapping a FileInputStream and specifying the correct character encoding.
    Edited by: sabre150 on Apr 29, 2009 2:13 PM

  • How to edit/update data into an XML file using Flex and Actionscript

    I can read an external xml file, please see the code below:
    protected function button1_clickHandler(event:MouseEvent):void
    var GrowthChartsDataGrid:XML;
    var loader:URLLoader = new URLLoader();
    var request:URLRequest = new URLRequest("../GrowthChartsDataGrid.xml");
        loader.load(request);
        loader.addEventListener(Event.COMPLETE, onComplete)
    function onComplete (event:Event)
         var loader:URLLoader = URLLoader(event.target);
         GrowthChartsDataGrid = new XML(loader.data);
         GrowthChartsDataGrid.GrowthChartGridView += <Month> {txtMonth.text} <Weight> {txtWeight.text} </Weight> </Month>
         texttesting.text = GrowthChartsDataGrid.toString();
    I can read an XML file and can add an extra node and can display it in a text filed. But I want to update the XML file contents which will come from the txtMonth and txtWeight text boxes.
    Please any suggestions???

    First of all thanks for your quick reply .
    I actually want to add another node inthe xml file. Files is at a local location and i can read the file and add an extra node (but I cant store this extra node in the actual XML file). But I want to save XML with the extra node.
    For exmaple,
    my current xml is:
    <?xml version="1.0" encoding="utf-8"?>
    <GrowthChartGridView>
        <Month> 1
        <Weight>3.5</Weight></Month>
    <Month> 2
        <Weight>3.9</Weight></Month>
    <Month> 3
        <Weight>4.5</Weight></Month>
    </GrowthChartGridView>
    and at run time, I can create a new node using the data from two textboxes at button click event.
         GrowthChartsDataGrid.GrowthChartGridView += <Month> {txtMonth.text} <Weight> {txtWeight.text} </Weight> </Month>
    Now what I want to do is, I want to add this node back in to my XML. Therefore, the result I am looking for is, my local XML should update like this.
    <?xml version="1.0" encoding="utf-8"?>
    <GrowthChartGridView>
        <Month> 1
        <Weight>3.5</Weight></Month>
    <Month> 2
        <Weight>3.9</Weight></Month>
    <Month> 3
        <Weight>4.5</Weight></Month>
    <Month> {txtMonth.text} <Weight> {txtWeight.text} </Weight> </Month>  //I can read data from text boxes so its fine but I can not store this in to                                                                                                          my original XML
    </GrowthChartGridView>
    Thanks

  • How to search and replace in an xml file using java

    Hi all,
    I am new to java and Xml Programming.
    I have to search and replace a value Suresh with some other name in the below xml file.
    Any help of code in java it is of great help,and its very urgent.
    I am using java swings for generating two text boxes and a button but i am not able to search in the xml file thru the values that are entered into these text boxes.
    Thanks in advance.
    **XML File*
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <student>
    <stud_name>Suresh</stud_name>
    <stud_age>40</stud_age>
    </student>Also i am using SAX Parser in the java program
    any help of code or any tutorials for sax parisng is very urgent please help me to resolve this problem
    Edited by: Karthik84 on Aug 19, 2008 1:45 AM
    Edited by: Karthik84 on Aug 19, 2008 3:15 AM

    Using XPath to locate the elements you are after is very easy.
    Try something like this:
    import java.io.File;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.xpath.XPath;
    import javax.xml.xpath.XPathConstants;
    import javax.xml.xpath.XPathFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.NodeList;
    import org.xml.sax.InputSource;
    public class BasicXMLReplaceWithDOM4J {
         static String inputFile = "C:/student.xml";
         static String outputFile = "C:/studentRenamed.xml";
         public static void main(String[] args) throws Exception {
              // Read xml and build a DOM document
              Document doc = DocumentBuilderFactory.newInstance()
                        .newDocumentBuilder().parse(new InputSource(inputFile));
              // Use XPath to find all nodes where student is named 'Suresh'
              XPath xpath = XPathFactory.newInstance().newXPath();
              NodeList nodes = (NodeList)xpath
                   .evaluate("//stud_name[text()='Suresh']", doc, XPathConstants.NODESET);
              // Rename these nodes
              for (int idx = 0; idx < nodes.getLength(); idx++) {
                   nodes.item(idx).setTextContent("Suresh-Renamed");
              // Write the DOM document to the file
              Transformer xformer = TransformerFactory.newInstance().newTransformer();
              xformer.transform(new DOMSource(doc), new StreamResult(new File(outputFile)));
    }- Roy

  • How to read specific lines from a text file using external table or any other method?

    Hi,
    I have a text file with delimited data, I have to pick only odd number rows and load into a table...
    Ex:
    row1:  1,2,2,3,3,34,4,4,4,5,5,5,,,5  ( have to load only this row)
    row2:   8,9,878,78,657,575,7,5,,,7,7
    Hope this is enough..
    I am using Oracle 11.2.0 version...
    Thanks

    There are various ways to do this.  I would be inclined to use SQL*Loader.  That way you can load it from the client or the server and you can use a SQL*Loader sequence to preserve the row order in the text file.  I would load the whole row as a varray into a staging table, then use the TABLE and MOD functions to load the individual numbers from only the odd rows.  Please see the demonstration below.
    SCOTT@orcl12c> HOST TYPE text_file.csv
    1,2,2,3,3,34,4,4,4,5,5,5,,,5
    8,9,878,78,657,575,7,5,,,7,7
    101,201
    102,202
    SCOTT@orcl12c> HOST TYPE test.ctl
    LOAD DATA
    INFILE text_file.csv
    INTO TABLE staging
    FIELDS TERMINATED BY ','
    TRAILING NULLCOLS
    (whole_row VARRAY TERMINATED BY '/n' (x INTEGER EXTERNAL),
    rn SEQUENCE)
    SCOTT@orcl12c> CREATE TABLE staging
      2    (rn         NUMBER,
      3     whole_row  SYS.OdciNumberList)
      4  /
    Table created.
    SCOTT@orcl12c> HOST SQLLDR scott/tiger CONTROL=test.ctl LOG=test.log
    SQL*Loader: Release 12.1.0.1.0 - Production on Tue Aug 27 13:48:37 2013
    Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.
    Path used:      Conventional
    Commit point reached - logical record count 4
    Table STAGING:
      4 Rows successfully loaded.
    Check the log file:
      test.log
    for more information about the load.
    SCOTT@orcl12c> CREATE TABLE a_table
      2    (rn       NUMBER,
      3     data  NUMBER)
      4  /
    Table created.
    SCOTT@orcl12c> INSERT INTO a_table (rn, data)
      2  SELECT s.rn,
      3         t.COLUMN_VALUE data
      4  FROM   staging s,
      5         TABLE (s.whole_row) t
      6  WHERE  MOD (rn, 2) != 0
      7  /
    17 rows created.
    SCOTT@orcl12c> SELECT * FROM a_table
      2  /
            RN       DATA
             1          1
             1          2
             1          2
             1          3
             1          3
             1         34
             1          4
             1          4
             1          4
             1          5
             1          5
             1          5
             1
             1
             1          5
             3        101
             3        201
    17 rows selected.

  • Appending Data in XML File using JAXB

    I need to write the 50,000 records into XML file. But at a time i need to write only 1000 records into XML. How do i append the data into XML using JAXB.

    I have tried but the data is written in the following way:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Users xmlns="http://www.yyyy.com/umc/importer/jaxb">
    <User id="101" xmlns="">
    <username>gjhs</username>
    <password>hdfhhdf</password>
    <role>df</role>
    <email>sdd</email>
    <phone>sdfdf</phone>
    <description>shkl</description>
    <property name="ernnker" value="hkdfhk"/>
    </User>
    </Users>
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Users xmlns="http://www.yyyy.com/umc/importer/jaxb">
    <User id="101" xmlns="">
    <username>gjhs</username>
    <password>hdfhhdf</password>
    <role>df</role>
    <email>sdd</email>
    <phone>sdfdf</phone>
    <description>shkl</description>
    <property name="ernnker" value="hkdfhk"/>
    </User>
    </Users>
    If i can eliminate the following lines from the above files then my job is done:
    </Users>
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Users xmlns="http://www.yyyy.com/umc/importer/jaxb">

  • How to read and parse a remote XML file with Java

    Hi.
    Using J2SE v1.4.2, I'd like to read and parse a remote file:
    http://foo.com/file.xml
    Is it possible with Java? I'd be extremely grateful if someone could provide me any webpage showing a very simple code.
    Thank you very much.

    How about the following?
         import java.io.InputStream;
         import java.net.URL;
         import javax.xml.parsers.DocumentBuilder;
         import javax.xml.parsers.DocumentBuilderFactory;
         import org.w3c.dom.Document;
         public static void main(String[] args) throws Exception {
              DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
              DocumentBuilder db = dbf.newDocumentBuilder();
              URL url = new URL("http://foo.com/file.xml");
              InputStream inputStream = url.openStream();
              Document document = db.parse(inputStream);
              inputStream.close();
         }-Blaise

  • Unmarshalling a DOM node to an XML file with JAXB

    I'm trying to unmarshall a DOM node to an XML file using JAXB. However I keep receiving a NullPointerException. This only seems to occur when I create the DOM Node from scratch. The stack trace looks like the following:
    java.lang.NullPointerException
            at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.startElement
    (SAXUnmarshallerHandlerImpl.java:87)
            at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:109)
            at com.sun.xml.bind.unmarshaller.DOMScanner.parse(DOMScanner.java:64)
            at com.sun.xml.bind.unmarshaller.UnmarshallerImpl.unmarshal(Unmarshaller
    Impl.java:149)
            at Main.main(Main.java:103)(If I unmarshal an XML file into a DOM node, I can successfully marshall the DOM node out to a new XML file using JAXB without error.)
    Any insight into what I am doing wrong would be greatly appreciated!
    Sample code and XSD follow...
    Sample Code:
    import itemlistsample.*;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Iterator;
    import java.util.List;
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.JAXBException;
    import javax.xml.bind.Marshaller;
    import javax.xml.bind.Unmarshaller;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.NodeList;
    import org.w3c.dom.Node;
    import org.w3c.dom.Text;
    public class Main
      public static void main(String[] args)
          try
              JAXBContext jc = JAXBContext.newInstance( "itemlistsample" );
              Unmarshaller u = jc.createUnmarshaller();
              * Set up DOM Node Document Object.
              DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
              dbf.setNamespaceAware(true);                   
              DocumentBuilder db = dbf.newDocumentBuilder(); 
              Document doc = db.newDocument();
              System.out.println();
              System.out.println();
              System.out.println("Create a DOM Node and unmarshall to an XML file");
              * Generate elements within DOM document
              Element itemListElt = (Element)doc.createElement("item_list");
              Element itemInfo = (Element)doc.createElement("item_info");
              Element name = (Element)doc.createElement("name");
              Element price = (Element)doc.createElement("price");
              * 3-Ring Binder @ 4.99
              name.appendChild(doc.createTextNode("3-Ring Binder"));
              itemInfo.appendChild(name);
              price.appendChild(doc.createTextNode("4.99"));
              itemInfo.appendChild(price);
              itemListElt.appendChild(itemInfo);
              * Large Paper Clips @ 1.23
              itemInfo = (Element)doc.createElement("item_info");
              name = (Element)doc.createElement("name");
              price = (Element)doc.createElement("price");
              name.appendChild(doc.createTextNode("Large Paper Clips"));
              itemInfo.appendChild(name);
              price.appendChild(doc.createTextNode("1.23"));
              itemInfo.appendChild(price);
              itemListElt.appendChild(itemInfo);
              doc.appendChild(itemListElt);
              * Display DOM document as a sanity check
              itemListElt = doc.getDocumentElement();
              System.out.println(itemListElt.getTagName());
              NodeList nl = itemListElt.getElementsByTagName("item_info");
              traverse("  ", nl.item(0));
              * Use JAXB to unmarshal the DOM document into
              * an instance of the generated JAXB class for
              * the root element.  Stack trace occurs here!
              ItemListType il = (ItemListType)u.unmarshal(doc);
              * Marshal to an XML file
              Marshaller m = jc.createMarshaller();
              m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
              m.marshal( il, new FileOutputStream("item_new.xml") );
          catch (Exception e)
         e.printStackTrace();
      public static void traverse(String indent, Node n)
        if (n != null)
          if (n.getNodeName() != null)
            System.out.println(indent + n.getNodeName());
            traverse(indent + "  ", n.getFirstChild());
          if (n.getNodeValue() != null)
            System.out.println(indent + n.getNodeValue());
          traverse(indent, n.getNextSibling());
    }Sample XSD:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
         <xsd:element name="item_list" type="ItemListType"/>
         <xsd:complexType name="ItemListType">
              <xsd:sequence>
                   <xsd:element name="item_info" type="ItemInfoType" maxOccurs="unbounded"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="ItemInfoType">
              <xsd:sequence>
                   <xsd:element name="name" type="xsd:string"/>
                   <xsd:element name="price" type="xsd:double"/>
              </xsd:sequence>
         </xsd:complexType>
    </xsd:schema>

    Modified schema
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="item_list">     
    <xsd:complexType>          
    <xsd:sequence>               
    <xsd:element ref="item_info" maxOccurs="unbounded"/>     
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="item_info">
         <xsd:complexType>          
    <xsd:sequence>               
    <xsd:element name="name" type="xsd:string"/>     
         <xsd:element name="price" type="xsd:double"/>     
         </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>

Maybe you are looking for

  • Problem with ITEM(:P1_REPORT_SEARCH)

    Hi! I have created a report-form using the wizard. I have an Item on the Report page which is of Type SELECT LIST WITH SUBMIT(Static), there are 2 values in the item namely : 'YES ' d,'Typformel' r and 'NO' d,'NO' r (:P1_X is Item name).(display null

  • Moving iTines to an external drive

    I want to take iTunes and move it in its entirety to an external drive. So far, I've only been able to copy the program and my music, not move it. Any ideas?

  • Ora-12203:TNS:unable to connect to destination

    Dear All Plz help me regarding this issue i got since many time and still i am unable to solve this problem properly problem is when i connect my form builder with oracle following error come and stop my working . ora-12203:TNS:unable to connect to d

  • Alert on Hyperion services down

    Hi, Could you please advice how to monitor Hyperion services if get down due to any reason? Will it possible to get email/alerts? Edited by: Kumar 1 on Dec 23, 2011 1:43 AM

  • Acrobat 8.1.2:scanning to pdf produce problem of appearance of black strip on right side of pdf doc

    I am using licensed Acrobat 8.1.2 Professional at notebook with XP Pro. I have trouble creating a PDF from scaner by using Acrobat 8.1.2, because of appearance of black strip on the right side on each page of pdf doc. Any help would be greatly apprec