Parsing .xsd files using DOM

Hi,
I am trying to parse a xsd file using DOM. The xsd has several nodes like
<xsd:complexType name="AccountLocate">
I want to extract the strings AccountLocate and AccountCategory and use them for further processing.
The hierarchy of the nodes is created without issues, but when I try to view the name and value of each node using getNodeName() and getNodeValue() method the node name I get and node value is as follows:
NODE-NAME NODE-VALUE NODE-TYPE
xsd:complexType null 1 //corresponds to the xsd:complexType node
#text 3 //corresponds to the AccountLocate node
Is there anyway (any DOM method for example) by which I can isolate the name AccountLocate?
Thanks and regards,
Prabal

Which parser is used for parsig?
With the DocumentBuilder parser set:
DocumentBuilderFactory factory
= DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);For parsing with the javax.xml.xpath.XPath class set the NamespaceContext on the XPath object.

Similar Messages

  • Problem while parsing xml file using DOM

    I have a xml file NewXML.xml. When I parse it I'm not getting the expected output: I'm trying to get only the value of the "name" tag. When I tried getElementByTagName("name"), I'm not getting the expected result.
    Here is my xml file based on a schema
    <?xml version="1.0" encoding="UTF-8"?>
    <student xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="NewXMLSchema.xsd">
    <name>john</name>
    <id>1000</id>
    </student>
    Coding:
    public static void main(String argv[])
    DocumentBuilderFactory factory =
    DocumentBuilderFactory.newInstance();
    Document document ;
    try {
    DocumentBuilder builder = factory.newDocumentBuilder();
    document = builder.parse( "NewXML.xml" );
    NodeList nodeList = (document.getElementsByTagName("name") );
    System.out.println(nodeList.getLength()+" node list "+nodeList.item(0));
    System.out.println(nodeList.item(0).getNodeValue());
    NodeList nodeList1 = nodeList.item(0).getChildNodes();
    System.out.println(nodeList1.getLength()+" node list "+nodeList1.item(0));
    System.out.println(nodeList1.item(0).getNodeValue());
    When I ran the above coding I got:
    1 node list [name: null]
    null
    1 node list [#text: name]
    name
    What should I do to get the result "john" inorder to change it
    Thanks
    rathi

    System.out.println(nodeList.item(0).getFirstChild().getNodeValue());

  • Updating XML file using DOM parser

    Hi,
    Can someone help me, how to update following XML file using DOM parser.
    The following is my XML file.
    <students>
         <student>
              <id>1</id>
              <name>abc</name>
         </student>
         <student>
              <id>2</id>
              <name>xyz</name>
         </student>
         <student>
              <id>3</id>
              <name/>
         </student>
         <student>
              <id>4</id>
              <name>ijk</name>
         </student>
         <student>
              <id>5</id>
              <name></name>
         </student>
    </students>Consider, I will input 2 fields, ie., id & name. For the matching Id, the name has to be updated.
    Though, I have achieved this, but I am unable to update the value for 3rd record, & 5th record ie., id=3 & id=5. Since, these are blank.
    Thanks.

    Some <name> elements have a child node which is a text node. From what you say it appears you know how to change those text nodes.
    The other <name> elements don't have any child nodes. But you want one. This suggests to me that you need code that creates a text node and adds it to the <name> element as its child.

  • Which parser do you  advice to parse .xsd files?

    Hello.
    I worked JSON files.
    And used gson and some likes parser.
    But know I need to parse .xsd files.
    Which parser do you advice to parse .xsd files?
    Thanks,
    Best regards,
    Babakishiyev

    Mr Babakishiyev wrote:
    Hello.
    I worked JSON files.
    And used gson and some likes parser.
    But know I need to parse .xsd files.
    Which parser do you advice to parse .xsd files?
    Thanks,
    Best regards,
    BabakishiyevJust curious, why would you want to 'parse' a .xsd file? Or do you want to parse a 'xml' file and then validate it against a xsd file that you have in java?

  • Parsing an XML using DOM parser in Java in Recursive fashion

    I need to parse an XML using DOM parser in Java. New tags can be added to the XML in future. Code should be written in such a way that even with new tags added there should not be any code change. I felt that parsing the XML recursively can solve this problem. Can any one please share sample Java code that parses XML recursively. Thanks in Advance.

    Actually, if you are planning to use DOM then you will be doing that task after you parse the data. But anyway, have you read any tutorials or books about how to process XML in Java? If not, my suggestion would be to start by doing that. You cannot learn that by fishing on forums. Try this one for example:
    http://www.cafeconleche.org/books/xmljava/chapters/index.html

  • Problem writing xml file using DOM

    Hi,
    I am trying to write a xml file using DOM. I am using xalan 2.5, xerces 1.4.4, jdk 1.3.1 in JRun 3 on windows.
    The code where I get exception :
                   TransformerFactory tFactory = TransformerFactory.newInstance();
                   Transformer transformer = tFactory.newTransformer();
                   transformer.transform(new DOMSource(doc), new StreamResult("pr.xml"));
    I get the runtime error as follows:
    javax.servlet.ServletException: null
    java.lang.NoSuchMethodError
         at org.apache.xml.utils.DOM2Helper.getNamespaceOfNodeDOM2Helper.java:342)
         at org.apache.xml.utils.TreeWalker.startNode(TreeWalker.java:387)
         at org.apache.xml.utils.TreeWalker.traverse(TreeWalker.java:202)
         at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:343)
    Thinking it is because of classpath, I placed xalan 2.5, xerces 1.4.4 jar files in jrun admin lib directory and in server lib directory as well. Still getting the same error.
    Any suggestion?
    Thanks in advance

    xalan is included in JRun 4. However JRun 3 does not.
    However I tried with the same code in JRun3 in different system. The error is completely different. I understand this is because of different version of files. trying to solve ;)
    Here my new exception
    javax.servlet.ServletException: org/w3c/dom/ranges/DocumentRange
    java.lang.NoClassDefFoundError: org/w3c/dom/ranges/DocumentRange
         at java.lang.ClassLoader.defineClass0(Native Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:493)
         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
         at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
         at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
         at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
         at java.lang.ClassLoader.defineClass0(Native Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:493)
         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
         at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
         at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
         at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
         at org.apache.xerces.jaxp.DocumentBuilderImpl.(Unknown Source)
         at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder(Unknown Source)
         at com.cybell.appl.deliveryorder.cmd.CreateXMLDOFile.createFile(CreateXMLDOFile.java:73)
         at com.cybell.appl.deliveryorder.cmd.CreateXMLDOFile.execute(CreateXMLDOFile.java:36)
         at com.cybell.appl.framework.cmd.BaseCommand.start(BaseCommand.java:50)
         at com.cybell.appl.framework.control.BaseController.service(BaseController.java:38)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
         at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1013)
         at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:925)
         at allaire.jrun.servlet.JRunNamedDispatcher.forward(../servlet/JRunNamedDispatcher.java:34)
         at allaire.jrun.servlet.Invoker.service(../servlet/Invoker.java:84)
         at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1013)
         at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:925)
         at allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDispatcher.java:88)
         at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1131)
         at allaire.jrun.servlet.JvmContext.dispatch(../servlet/JvmContext.java:330)
         at allaire.jrun.http.WebEndpoint.run(../http/WebEndpoint.java:107)
         at allaire.jrun.ThreadPool.run(../ThreadPool.java:272)
         at allaire.jrun.WorkerThread.run(../WorkerThread.java:75)

  • Parsing .xfdl file using c#

    Hello All,
    I am developing app using c#. Can any one please help me how can I parsing .xfdl file using c#? Actually I want to read value from .xfdl file and show. how can I do this please help me.
    ThanQ
    Ganesh

    Hello All,
    I am developing app using c#. Can any one please help me how can I parsing .xfdl file using c#? Actually I want to read value from .xfdl file and show. how can I do this please help me.
    ThanQ
    Ganesh
    You'd better connect IBM for how to read xfdl file.
    remember make the reply as answer and vote the reply as helpful if it helps.

  • Error  in parsing xsd schema using jaxb !!

    I want to parse an xsd which contains links to other schema (.xsd) files. in the following format along with other things :
    <xsd:include schemaLocation="fgdc-std-001-1998-sect01.xsd" />
    <xsd:include schemaLocation="fgdc-std-001-1998-sect02.xsd" />
    <xsd:include schemaLocation="fgdc-std-001-1998-sect03.xsd" />
    <xsd:include schemaLocation="fgdc-std-001-1998-sect04.xsd" />
    <xsd:include schemaLocation="fgdc-std-001-1998-sect05.xsd" />
    <xsd:include schemaLocation="fgdc-std-001-1998-sect06.xsd" />
    <xsd:include schemaLocation="fgdc-std-001-1998-sect07.xsd" />
    <xsd:include schemaLocation="fgdc-std-001-1998-sect08.xsd" />
    <xsd:include schemaLocation="fgdc-std-001-1998-sect09.xsd" />
    <xsd:include schemaLocation="fgdc-std-001-1998-sect10.xsd" />
    But when i issue the xjc command, an error occours saying
    [ERROR] In "strict" mode, the following schema feature is not allowed (See App E
    .2).Use the "-extension" switch:
    <key>
    line 127 of fgdc-std-001-1998-sect02.xsd
    I don't understand what the error means.................................Any help in this regard shall be sincerely appreciated.
    Thanks in Advance,
    Bibhusan

    ERROR] In "strict" mode, the following schema feature is not allowed (See App E
    .2).Use the "-extension" switch:
    <key>
    line 127 of fgdc-std-001-1998-sect02.xsd
    Some of the schema constructs xs:any, xs:anyAttribute, xs:key, xs:keyref, xs:unique are not supported
    by Jaxb.

  • Problem in parsing JMS TextMessages using DOM

    Hi
    I want to parse JMS TextMessages by using DOM parser.DomBuilder's parse method supports only Strings,input stream in its constructor.
    Is there anyway we can parse JMS TextMessages by using DOM.Your help would be appreciated.
    Thanks
    Kanth

    kanth218 wrote:
    Hi
    DomBuilder's parse method supports only Strings,input stream in its constructor.This is not true. Have another look at the documentation.
    Is there anyway we can parse JMS TextMessages by using DOM.Your help would be appreciated.
    parse(new InputSource(new StringReader(someString)))

  • Delete elements from XML file using DOM and java

    Hi
    I want now is to remove element from my XML file
    for example
    i have following xml
    <?xml version="1.0" encoding="UTF-8"?>
    <printing>
    <firstLineTexts>
              <firstLineText />
              <firstLineText>|line11</firstLineText>
              <firstLineText>|line12</firstLineText>
    </firstLineTexts>
    </printing>how do i remove all elements fireLineText
    my final output should be
    <?xml version="1.0" encoding="UTF-8"?>
    <printing>
    <firstLineTexts>
    </firstLineTexts>
    </printing>How do i do it using DOM,
    I can create instance of DOM and write it using TransformerFactory
    Ashish

    Hi
    I am trying the following code,
    but it is not working
                    NodeList nScene = doc.getElementsByTagName("firstLineTexts");
              NodeList nScene1 = nScene.item(0).getChildNodes();
              for (int i = 0; i < nScene1.getLength(); i++)
                   Node n = nScene1.item(i);
                        nScene.item(0).removeChild(n);
              }

  • How to remove element namespaces in XML file using DOM or SAX?

    Hi Guys,
    I developed a JAVA mapping in XI to add name spaces for XML file, after mapping,name spaces xmlns="http://www.mro.com/mx/integration" and xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" were added correctly, but for some nodes, such as <Header> and <Content>, a name space xmlns="" was added automatically.Please check below files to compare.
    It looks like be added automatically by XI. I didn't process anything for these nodes in JAVA program.
    Now the issue is, how can I remove these redundant namespaces? Such as xmlns="".
    Can I remove them using DOM or SAX in JAVA Mapping?
    Thanks in advance.
    ====>Original XML file
    <?xml version="1.0" encoding="UTF-8"?>
    <LLYLPPInterface language="EN">
       <Header>
          <SenderID>GBIP</SenderID>
          <CreationDateTime>2008-02-13T22:49:34-05:00</CreationDateTime>
          <RecipientID/>
          <MessageID/>
       </Header>
       <Content>
          <LLY-LPP>
             <INVOICE>
                <INVOICELINE>
                   <PONUM>4780000008</PONUM>
                   <POLINENUM>1</POLINENUM>
                   <INVOICEQTY>1</INVOICEQTY>
                   <LOADEDCOST>68</LOADEDCOST>
                </INVOICELINE>
             </INVOICE>
          </LLY-LPP>
       </Content>
    </LLYLPPInterface>
    ===>Target XML file after JAVA mapping
    <?xml version="1.0" encoding="utf-8"?>
    <LLYLPPInterface language="EN" xmlns="http://www.mro.com/mx/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <Header xmlns="">
              <SenderID>GBIP</SenderID>
              <CreationDateTime>2008-02-13T23:11:55-05:00</CreationDateTime>
              <RecipientID/>
              <MessageID/>
         </Header>
         <Content xmlns="">
              <LLY-LPP>
                   <INVOICE>
                        <INVOICELINE>
                             <PONUM>4780000008</PONUM>
                             <POLINENUM>0</POLINENUM>
                             <INVOICEQTY>1</INVOICEQTY>
                             <LOADEDCOST>68</LOADEDCOST>
                        </INVOICELINE>
                   </INVOICE>
              </LLY-LPP>
         </Content>
    </LLYLPPInterface>
    Edited by: Eddie Zhang on Feb 14, 2008 9:22 AM
    Edited by: Eddie Zhang on Feb 14, 2008 9:24 AM

    Hi Milan,
    Thanks for your replay.
    Actually when I used module XMLAnonymizerBean to convert namespaces, the header of XML, such as <?xml version="1.0" encoding="UTF-8"?> was converted to format <?xml version='1.0' encoding='UTF-8'?>, quote was converted to single quote. Although I set parameter anonymizer.quote = ", it still didn't work, single quote appeared instead of quote.
    I'm not sure why this happened. Can anyone help to clarify this?
    Thanks
    Edited by: Eddie Zhang on Feb 15, 2008 2:11 AM

  • Parse owl file using jena

    please, if anyone can help me... i am pretty desperate..
    i have to find a parser for an owl file using jena and i can't manage it. PLease if anyone can help me with some detailed code and how to use it(how to make java recognize jena,etc...)
    thank you in advance
    poli

    A lot of the information needed to parse a file can be found @ http://jena.sourceforge.net/
    I have also added an example of how to create the parse below to create the ontology model.
    OntDocumentManager mgr = new OntDocumentManager("file:/[destination]/ont-policy.rdf");
    OntModelSpec s = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
    s.setDocumentManager(mgr);
    OntModel m = ModelFactory.createOntologyModel(s, null);
    m.read("file:/" + [file to be read], null);Hope this helps

  • How to generate .xsd file using jaxb generated java files

    Hi,
    We need to upgrade our applicatio to jdk1.6 which has jaxb2.0 class files in it. Our application has java files generated from .xsd using jaxb1.0.2 version. At present we dont have .xsd or .xml file with us.
    We decide to generate .xsd file by using jaxb1.0.2 generated java files. I tried using schemagen.exe given by jdk1.6 to generate .xsd file. It error out. Is there any other way to generate .xsd file ?
    pls let me know.
    thanks,
    Thiru

    Object-XML mapping is a new feature in JAXB 2.0. Classes generated with JAXB 1.0 won't generate a schema.
    Generate Java classes with JAXB 2.0 xjc.
    http://www.theregister.co.uk/2006/09/22/jaxb2_guide/

  • Store and load objects to XML files using DOM

    Hello everybody,
    a quick question for all of you.
    I'm designing a desktop application which requires a lot of custom objects to be stored into XML files and later reloaded from them. I'm planning to use DOM, creating an interface like this:
    public interface StorableAsDom
    // Create an object from a DOM tree
    static Object createFromDom(org.w3c.dom.Node root) throws InvalidDomException;
    // Get the DOM tree for an object
    org.w3c.dom.DocumentFragment getDomTree(org.w3c.dom.Document doc) throws DOMException;
    Then, every class which needs to be saved should implement the above interface. This way everything works fine.
    My question is: do you know any available java package which already provides similar functionalities?
    I'd like not to reinvent the wheel if I can; time is always a critical factor.
    Thanks in advance to all of you.
    Cheers
    marcocaco

    Hi,
    When I need object -xml binding, I usually have two methods -
    one for reading & one for writing (the "VOs" below stands for "Value Objects" [getters/setters & empty constructor only]):
    READ: loadXML (= XML2VOs)
    1.XML2DOM - this method can be generic
    2.DOM2VOs - populate your VOs from the DOM just obtained in 1.
    WRITE: saveXML (=VOs2XML)
    1.VOs2DOM - create a new DOM document from your VOs' fields.
    2.DOM2XML - this method can be generic
    It would be nice (but dificult & not very elegant) to make DOM2VOs & VOs2DOM generic. If such methods will be written, they should be combined with the XML2DOM & DOM2XML (resp.) & then you would have two generic methods XML2VOs & VOs2XML... (Alternativelly, you can get Sun's JAXB package which does object-xml binding but this is not part of the JDK 5)
    If what I have outlined above sounds like what you want to do, let me know if you want more details (eg. how the DOM2VOs would be implemented etc)...

  • How to parse ".dat" file using java?

    Hi experts/friends,
    I need to parse the ".dat" files such as "history.dat" of Firefox history and "index.dat" of IE history...
    I cannot able to parse those files.
    Can anyone suggest me or help me....

    Google ( [url http://www.google.com/search?q=firefox+history+file+format]firefox history file format )
    Google ( [url http://www.google.com/search?q=internet+explorer+history+file+format]internet explorer history file format )

Maybe you are looking for

  • Design a report for mainframes data.

    Hello All, I was given a requirement to design a report using BI Publisher to burst emails with attachments, where the input file is coming from Mainframes ( fixed positioning text file which also includes the context of the attachments). The record

  • Phantom Files!

    I accidentally posted this somewhere else, but it works best here. We use Quark 5 in Classic Mode on our G5s running OS X (10.3.x). Whenever we use one of the Classic Mode dialog boxes, like Open or Save As, we see files that don't exist. I can visua

  • MQ error: MQJMS2007

    Team, We just upgrade from PI 7.0 SP11 to SP12 and all our MQ screnario are not fonctionning anymore ... we are getting the MQJMS2007 error (see below) Any hints will be appreciated !! A+ Delivery of the message to the application using connection JM

  • Enabling ports and services with svccfg

    Hi, I had a problem today which appears to have been a result of running jass security hardening on a system. The webconsole failed to restart, it was eventualy resolved by # svccfg -s svc:/system/webconsole setprop options/tcp_listen = true # svcadm

  • HT4539 Where is the "authorize this computor button"  in the iTunes store

    Where is the "authorize this computor" button located, in the iTunes Store?