Parsing my xml using XMLBeans

I'm trying to use XMLBeans to load my xml file and access different elements of it. Here is my schema:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://testing.jsm.jtsd.com/testData"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="Hazard">
<xs:complexType>
<xs:sequence>
<xs:element name="Type" type="xs:string"/>
<xs:element name="Name" type="xs:string"/>
<xs:element name="LatLonLocation" type="xs:string"/>
<xs:element name="ZuluTime" type="xs:string"/>
<xs:element name="Agent" type="xs:string"/>
<xs:element name="Munition" type="xs:string"/>
<xs:element name="DeliveryMethod" type="xs:string"/>
<xs:element name="DispersalDevice" type="xs:int"/>
<xs:element name="TypeMatl" type="xs:string"/>
<xs:element name="MatlForm" type="xs:string"/>
<xs:element name="TypeMatlAmt" type="xs:int"/>
<xs:element name="MatlMass" type="xs:double"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Here is my xml file:
<Hazard xmlns="http://testing.jsm.jtsd.com/testData">
<Type>TestHazard</Type>
<Name>Test_default</Name>
<LatLonLocation>20 N 20 E</LatLonLocation>
<ZuluTime>180200ZOCT2007</ZuluTime>
<Agent>GB</Agent>
<Munition>500 kg Bomb</Munition>
<DeliveryMethod>4 AC * 8 Bombs</DeliveryMethod>
</Hazard>
I can run scomp and generate a xmlbeans jar file.
When I try to load my xml file, I get this error:
org.apache.xmlbeans.XmlException: error: Unexpected element: CDATA
Here is my java code that tries to load my xml file and errors out:
HazardDocument myParsedDoc =
HazardDocument.Factory.parse(myXmlFile);
Please let me know what I'm doing wrong.

Thanks for the reply. And sorry for the confusion. I am passing a File to that method call. I've been working on this for awhile and I'm about to go back to JaxB.
My xsd snippet looks like this now:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://testing.jsm.jtsd.com">
<xs:element name="JSMData">
<xs:complexType>
<xs:sequence>
<xs:element name="Hazard" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Type" type="xs:string"/>
<xs:element name="Name" type="xs:string"/>
I"m able to System out the JSMDataDocument and JSMData after my xml file gets parsed and I can see my xml printed out correctly, but when I do JSMData.sizeOfHazardArray , I get 0 when I should be getting 5 (1 for each Hazard element in my xml file).
Here is my xml file snippet:
<JSMData xmlns="http://testing.jsm.jtsd.com">
<Hazard>
<Type>RaWnHazard</Type>
<Name>RW_large_foo</Name>
Anything wrong here?

Similar Messages

  • Problem in parsing an XML using SAX parser

    Hai All,
    I have got a problem in parsing an XML using SAX parser.
    I have an XML (sample below) which need to be parsed
    <line-items>
    <item num="1">
         <part-number>PN1234</part-number>
         <quantity uom="ea">10</quantity>
         <lpn>LPN1060</lpn>
         <reference num="1">Line ref 1</reference>
         <reference num="2">Line ref 2</reference>
         <reference num="3">Line ref 3</reference>
    </item>
    <item num="2">
         <part-number>PN1527</part-number>
         <quantity uom="lbs">5</quantity>
         <lpn>LPN2152</lpn>
         <reference num="1">Line ref 1</reference>
         <reference num="2">Line ref 2</reference>
         <reference num="3">Line ref 3</reference>
    </item>
    <item num="n">
    </item>
    </line-items>
    There can be any number of items( 1 to n). I need to parse these
    item values using SAX parser and invoke a stored procedure for
    each item with its
    values(partnumber,qty,lpn,refnum1,refnum2,refnum3).
    Suppose if there are 100 items, i need to invoke the stored
    procedure sp1() 100 times for each item.
    I need to invoke the stored procedure in endDocument() method of
    SAX event handler and not in endelement() method.
    What is the best way to store those values and invoke the stored
    procedure in enddocument() method.
    Any help would br greatly appreciated.
    Thanks in advance
    Pooja.

    VO or ValueObject is a trendy new name for Beans.
    So just create an item class with variables for each of the sub elements.
    <item>
    <part-number>PN1234</part-number>
    <quantity uom="ea">10</quantity>
    <lpn>LPN1060</lpn>
    <reference num="1">Line ref 1</reference>
    <reference num="2">Line ref 2</reference>
    <reference num="3">Line ref 3</reference>
    </item>
    public class ItemVO
    String partNumber;
    int quantity;
    String quantityType;
    String lpn;
    List references = new ArrayList();
    * @return Returns the lpn.
    public String getLpn()
    return this.lpn;
    * @param lpn The lpn to set.
    public void setLpn(String lpn)
    this.lpn = lpn;
    * @return Returns the partNumber.
    public String getPartNumber()
    return this.partNumber;
    * @param partNumber The partNumber to set.
    public void setPartNumber(String partNumber)
    this.partNumber = partNumber;
    * @return Returns the quantity.
    public int getQuantity()
    return this.quantity;
    * @param quantity The quantity to set.
    public void setQuantity(int quantity)
    this.quantity = quantity;
    * @return Returns the quantityType.
    public String getQuantityType()
    return this.quantityType;
    * @param quantityType The quantityType to set.
    public void setQuantityType(String quantityType)
    this.quantityType = quantityType;
    * @return Returns the references.
    public List getReferences()
    return this.references;
    * @param references The references to set.
    public void setReferences(List references)
    this.references = references;

  • 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

  • Issue in parsing an XML using kxml in Creme 4.1 JVM for WIndows CE

    Hi,
    I have written a code to parse an XML using KXML.jar.
    The code will read the XML file, parse the content and writes data to a text file.
    The code is working fine in normal Windows XP enviroment.
    The same code when tested in a pocket PC is not writing the content and also not throwing any error or exception.
    Please give me some inputs on how to resove this issue.
    TIA,
    shubakarthik

    Hi,
    I have written a code to parse an XML using KXML.jar.
    The code will read the XML file, parse the content and writes data to a text file.
    The code is working fine in normal Windows XP enviroment.
    The same code when tested in a pocket PC is not writing the content and also not throwing any error or exception.
    Please give me some inputs on how to resove this issue.
    TIA,
    shubakarthik

  • Problem in parsing an xml using DOM parser.

    Hi,
        I have created an action block for client.
        it  takes a xml file present on D drive and generates a pdf by parsing the xml file.
        My code was working perfectly fine till yesterday.
    But now i getting , [INFO ]: Error-- Premature end of file.  org.xml.sax.SAXParseException: Premature end of file.
    But xml is perfectly fine. Also the code work from eclipse.
    Need some inputs on this.
    Regards,
    Vishal Jadhav
    Edited by: vishal jadhav on Jan 23, 2009 9:49 AM

    Vishal,
    what exactly did you change? How do you call the action block? What version/Support package/Build of MII do you use?
    Have you see the following thread? There a user had the same message which was caused by missing credentials.
    [https://forums.sdn.sap.com/click.jspa?searchID=21364701&messageID=6756453]
    Michael
    Edited by: Michael Otto on Jan 23, 2009 11:57 AM

  • Parsing a XML using Jdom --- Problem pls help

    Hi all,
    I am reposting it as I was told to format the code and send it again.
    I am trying to parse a xml file using a jdom java code.This code works fine if I remove xmlns attribute in the root element. (I get the expected result) .If the "xmlns" attribute is put in the xml as it should be then the parsing and retrieving returns null. Please tell me how to fix this issue.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Xml
    <process name="CreateKBEntryService" targetNamespace="http://serena.com/CreateKBEntryService" suppressJoinFailure="yes" xmlns:tns="http://serena.com/CreateKBEntryService" xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:bpelx="http://schemas.oracle.com/bpel/extension" xmlns:ora="http://schemas.oracle.com/xpath/extension" xmlns:nsxml0="http://localhost:8080/axis/services/CreateKBEntryService" xmlns:nsxml1="http://DefaultNamespace" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
    <partnerLinks>
    <partnerLink name="client" partnerLinkType="tns:CreateKBEntryService" myRole="CreateKBEntryServiceProvider"/>
    <partnerLink name="CreateKBEntryPartnerLink" partnerLinkType="nsxml0:CreateKBEntryLink" partnerRole="CreateKBEntryProvider"/>
    </partnerLinks>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
    Java:
    import java.io.*;
    import java.util.*;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.input.SAXBuilder;
    public class sample1 {
    public static void main(String[] args) throws Exception {
    // create a XML parser and read the XML file
    SAXBuilder oBuilder = new SAXBuilder();
    Document oDoc = oBuilder.build(new File("**xml file location**"));
    Element root = oDoc.getRootElement();
    System.out.println(root.getName());
    String tgtns= root.getAttributeValue("targetNamespace");
    System.out.println("tgt ns "+ tgtns);
    List list= root.getChildren("partnerLinks");
    Iterator it1= list.iterator();
    System.out.println("Iterator 1 - "+list.size());
    while(it1.hasNext()){
    Element partnerlinks = (Element)it1.next();
    List list2= partnerlinks.getChildren("partnerLink");
    System.out.println("iterator 2 - "+list2.size());
    }~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Result:
    Without Xmlns in xml file(Expected and correct output)
    process
    tgt ns http://serena.com/CreateKBEntryService
    Iterator 1 - 1//expected and correct result that comes when I remove xmlns attribute from xml
    iterator 2 - 2
    Result with xmlns:
    process
    tgt ns http://serena.com/CreateKBEntryService
    Iterator 1 - 0 //instead of 0 should return 1

    One suggestion to try:
    Change your code to the following
    Element root = oDoc.getRootElement();
    System.out.println(root.getName());
    String tgtns= root.getAttributeValue("targetNamespace");
    System.out.println("tgt ns "+ tgtns);
    Namespace ns = Namespace.getNamespace(
      "http://schemas.xmlsoap.org/ws/2003/03/business-process/" );
    List list= root.getChildren("partnerLinks", ns );
    Iterator it1= list.iterator();
    System.out.println("Iterator 1 - "+list.size());The JavaDoc says for the one-arg getChildren()
    If this target element has no nested elements with the given name outside a namespace, an empty List is returned.
    Your elements have a namespace (the default one) so it should be worth a try.
    Dave Patterson

  • Problem parsing a xml using Jdom

    Hi all,
    I am reposting it as I was told to format the code and send it again.
    I am trying to parse a xml file using a jdom java code.This code works fine if I remove xmlns attribute in the root element. (I get the expected result) .If the "xmlns" attribute is put in the xml as it should be then the parsing and retrieving returns null. Please tell me how to fix this issue.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Xml
    <process name="CreateKBEntryService" targetNamespace="http://serena.com/CreateKBEntryService" suppressJoinFailure="yes" xmlns:tns="http://serena.com/CreateKBEntryService" xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:bpelx="http://schemas.oracle.com/bpel/extension" xmlns:ora="http://schemas.oracle.com/xpath/extension" xmlns:nsxml0="http://localhost:8080/axis/services/CreateKBEntryService" xmlns:nsxml1="http://DefaultNamespace" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
    <partnerLinks>
    <partnerLink name="client" partnerLinkType="tns:CreateKBEntryService" myRole="CreateKBEntryServiceProvider"/>
    <partnerLink name="CreateKBEntryPartnerLink" partnerLinkType="nsxml0:CreateKBEntryLink" partnerRole="CreateKBEntryProvider"/>
    </partnerLinks>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
    Java:
    import java.io.*;
    import java.util.*;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.input.SAXBuilder;
    public class sample1 {
    public static void main(String[] args) throws Exception {
    // create a XML parser and read the XML file
    SAXBuilder oBuilder = new SAXBuilder();
    Document oDoc = oBuilder.build(new File("**xml file location**"));
    Element root = oDoc.getRootElement();
    System.out.println(root.getName());
    String tgtns= root.getAttributeValue("targetNamespace");
    System.out.println("tgt ns "+ tgtns);
    List list= root.getChildren("partnerLinks");
    Iterator it1= list.iterator();
    System.out.println("Iterator 1 - "+list.size());
    while(it1.hasNext()){
    Element partnerlinks = (Element)it1.next();
    List list2= partnerlinks.getChildren("partnerLink");
    System.out.println("iterator 2 - "+list2.size());
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Result:
    Without Xmlns in xml file(Expected and correct output)
    process
    tgt ns http://serena.com/CreateKBEntryService
    Iterator 1 - 1//expected and correct result that comes when I remove xmlns attribute from xml
    iterator 2 - 2
    Result with xmlns:
    process
    tgt ns http://serena.com/CreateKBEntryService
    Iterator 1 - 0 //instead of 0 should return 1

    One suggestion to try:
    Change your code to the following
    Element root = oDoc.getRootElement();
    System.out.println(root.getName());
    String tgtns= root.getAttributeValue("targetNamespace");
    System.out.println("tgt ns "+ tgtns);
    Namespace ns = Namespace.getNamespace(
      "http://schemas.xmlsoap.org/ws/2003/03/business-process/" );
    List list= root.getChildren("partnerLinks", ns );
    Iterator it1= list.iterator();
    System.out.println("Iterator 1 - "+list.size());The JavaDoc says for the one-arg getChildren()
    If this target element has no nested elements with the given name outside a namespace, an empty List is returned.
    Your elements have a namespace (the default one) so it should be worth a try.
    Dave Patterson

  • Problem in parsing XML using DOM Parser.

    Hi,
    I am parsing an XML using DOM Parser.
    When i try to get attributes of a node, i dont get in the order it is written. For Eg. This the node:
    <Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa">
    When i try to print the attribute values i should get in the order:
    News, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, 202, COGN-4MNMT3, aaaa
    BUT I AM GETTING IN THE ORDER:
    News, 202, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, aaaa, COGN-4MNMT3
    Is there any way to sort this problem out?
    Thanks and Regards,
    Ashok

    Hi Guys,
    Thanks a lot for your replies.
    But i want to keep all the values as attributes only.
    the XML file is as shown below:
    <Menu>
    <Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa" children="3">
         <Level1 label="ING News" link="" level="1" uid="COGN-4MNN89" parentid="COGN-4MNMT3" children="3" >
              <Level2 label="All ING News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="2" uid="INGD-4MVTK2" parentid="COGN-4MNN89" children="0">
              </Level2>
    </Level1>
    </Level0>
    The code i was using to get attributes is:
    String strElementName = new String(node.getNodeName());
         // System.out.println("strElementName:"+node.getNodeName());
    NamedNodeMap attrs = node.getAttributes();
    if (attrs != null) {
    int iLength = attrs.getLength();
    for (int i = 0; i < iLength; i++) {
    String strAttributes = (String) attrs.item(i).getNodeName();
    String strValues = (String) attrs.item(i).getNodeValue();
    Also is it not possible to Enforce the order using some Schema/DTD in this case?
    TIA
    Ashok

  • Error in Parsing XML using fx:XML/ [Error- 1090: XML parser failure: element is malformed]

    Hi All,
    I am getting error while loading XML in <fx:XML> tag.
    Error:
    TypeError: Error #1090: XML parser failure: element is malformed.
    MXML Code:
    <fx:Declarations>
    <fx:XML id="xmlSource2" source="sample.xml"/>
    </fx:Declarations>
    Sample XML Used: (sample.xml)
    <?xml version="1.0" encoding="UTF-8"?>
    <File>
        <Chemical id="000035676" displayFormula="C39-H45-N2-O6"
            displayName="Dimethyltubocurarine">
            <NameList>
                <NameOfSubstance>
                    Dimethyltubocurarine
                    <SourceList>
                        <Source>MESH</Source>
                    </SourceList>
                </NameOfSubstance>
                <SystematicName>
                    Tubocuraranium, 6,6',7',12'-tetramethoxy-2,2',2'-trimethyl-
                    <SourceList>
                        <Source>NLM</Source>
                    </SourceList>
                </SystematicName>
                <Synonyms>
                    Dimethyltubocurarine
                    <SourceList>
                        <Source>NLM</Source>
                    </SourceList>
                </Synonyms>
                <Synonyms>
                    Dimethyltubocurarinium
                    <SourceList>
                        <Source>NLM</Source>
                    </SourceList>
                </Synonyms>
                <Synonyms>
                    Methyltubocurarinum
                    <SourceList>
                        <Source>NLM</Source>
                    </SourceList>
                </Synonyms>
            </NameList>
            <NumberList>
                <CASRegistryNumber>
                    35-67-6
                    <SourceList></SourceList>
                </CASRegistryNumber>
                <RelatedRegistryNumber>
                    518-26-3 (iodide.hydriodide)
                    <SourceList>
                        <Source>MESH</Source>
                    </SourceList>
                </RelatedRegistryNumber>
            </NumberList>
            <ClassificationList>
                <ClassificationCode>
                    Neuromuscular nondepolarizing agents
                    <SourceList>
                        <Source>MESH</Source>
                    </SourceList>
                </ClassificationCode>
            </ClassificationList>
            <FormulaList>
                <MolecularFormula>
                    C39-H45-N2-O6
                    <SourceList>
                        <Source>NLM</Source>
                    </SourceList>
                </MolecularFormula>
            </FormulaList>
            <FormulaFragmentList></FormulaFragmentList>
            <NoteList></NoteList>
            <LocatorList>
                <FileLocator
                    url="http://cnetdb.nci.nih.gov/cgi-bin/srchcgi.exe?DBID=****3&SFMT=****_basic%2F10%2F0%2F0&TYPE=search&SRCHFORM=passthru%3D%Asrchform%3ASRCH%3A&FIELD_001=[CAS]35-67-6&#38;GoButton=Search&#38;FIELD_001_CTL=EXPR&#38;FIELD_908=&#38;FIELD908_CTL=HASABSTRACT&#38;FIELD_903=&#38;FIELD_903_CTL=YEARFORE&#38;DOCPAGE=10">CANCERLIT</FileLocator>
                <FileLocator
                    url="http://toxnet.nlm.nih.gov/cgi-bin/sis/search/r?dbs+toxline:@and+@term+@rn+35-67-6+@term+@org+DART">DART/ETIC</FileLocator>
                <FileLocator
                    url="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=search&db=PubMed&term=35-67-6[ECNO]+OR+&#34;~&#34;[MH]">MEDLINE</FileLocator>
                <FileLocator
                    url="http://www.nlm.nih.gov/cgi/mesh/2K/MB_cgi?term=35-67-6&rn=1">MESH</FileLocator>
                <FileLocator
                    url="http://toxnet.nlm.nih.gov/cgi-bin/sis/search/r?dbs+toxline:@term+@rn+35-67-6+@OR+@mh+""">TOXLINE</FileLocator>
            </LocatorList>
        </Chemical>
    </File>
    Also, when I am using HttpService to load same XML I am getting no such error!!
    <s:HTTPService id="employeeService"
                           url="sample.xml"
                           result="employeeService_resultHandler(event)"
                           fault="employeeService_faultHandler(event)"/>
    Please help!!
    Thanks.
    Abhinav

    I think url in XML is creating problem here.
    <FileLocator
                    url="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=search&db=PubMed&term=23-95-0[ECNO]+OR+&#34;~&#34;[MH]">MEDLINE</FileLocator>
    Is there any way to parse this XML using <fx:XML/> ??
    Thanks.

  • Parsing itunes:duration using xpath

    Hi,
    I have my xml structured like this
    <?xml version="1.0" encoding="utf-8"?>
    <rss xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd" version="2.0">
    <channel>
    <title>938LIVE Budget 2007</title>
    <itunes:author>938LIVE </itunes:author>
    <link>http://www.938live.sg</link>
    <description>Budget statement, forum and stories</description>
    <itunes:subtitle>Budget statement, forum and stories</itunes:subtitle>
    <itunes:summary>Budget statement, forum and stories</itunes:summary>
    <language>en-us</language>
    <managingEditor>[email protected]</managingEditor>
    <webMaster>[email protected] (938LIVE )</webMaster>
    <generator>The Podcast RSS Buddy 3.0 http://www.tolley.info/rssbuddy/index.html</generator>
    <copyright>(c) 2007 938LIVE </copyright>
    <itunes:explicit>no</itunes:explicit>
    <itunes:owner><itunes:name>938LIVE </itunes:name>
    <itunes:email>[email protected]</itunes:email></itunes:owner>
    <image><url>http://www.podcast.sg/938LIVE/logo.jpg</url><title>938LIVE Budget 2007</title><link>http://www.938live.sg</link></image>
    <itunes:link rel="image" type="video/jpeg" href="http://www.podcast.sg/938LIVE/logo.jpg">938LIVE Budget 2007</itunes:link>
    <category>News</category>
    <itunes:category text="News">
    </itunes:category>
    <pubDate>Thu, 15 Feb 2007 20:16:26 +0800</pubDate>
    <lastBuildDate>Thu, 15 Feb 2007 20:16:26 +0800</lastBuildDate>
    <item>
    <title>Budget Forum Part 2</title>
    <itunes:author>938LIVE </itunes:author>
    <link>http://www.938live.sg</link>
    <description><![CDATA[<br>Budget Forum 2007 Part 2<BR>]]></description>
    <itunes:subtitle>Budget Forum 2007 Part 2</itunes:subtitle>
    <itunes:summary>Budget Forum 2007 Part 2</itunes:summary>
    <author>[email protected]</author>
    <pubDate>Thu, 15 Feb 2007 20:16:26 +0800</pubDate>
    <category>News</category>
    <enclosure url="http://www.podcast.sg/938LIVE/Budget2007/audio/budgetForum2_150207.mp3" length="22579700" type="MP3"/>
    <guid isPermaLink="false">RSS_BUDDY_247119-528</guid>
    <itunes:category text="News">
    </itunes:category>
    <itunes:explicit>no</itunes:explicit>
    <itunes:duration>00:25:16</itunes:duration>
    <itunes:keywords>MediaCorp Radio 938LIVE</itunes:keywords>
    <comments>MediaCorp Radio 938LIVE</comments>
    </item>
    </channel>
    </rss>
    What I would like to do is parse the XML using the Xpath and I have succeeded parse the <item> but yet for another tag with a <aaa:bbb> structure.
    This is my code to get the first item title:
    expression = "/rss/channel/item[0]/title";
    xPathExpression = xPath.compile(expression);
    try {
    inputSource = new InputSource(new FileInputStream(xmlDocument));
    } catch (FileNotFoundException ex) {
    ex.printStackTrace();
    String itemValue = xPathExpression.evaluate(inputSource);
    System.out.println(itemValue);
    However, I was unable to get the data for the <itunes:duration> tag for my expression even when i'm using the expression "/rss/channel/item[0]/itunes:duration"
    Please advise since i need it ASAP
    Thanks & Regards,
    Deddy Johari

    The following code should work:
    private class NamespaceContextMap extends HashMap<String,String> implements NamespaceContext {
            public String getNamespaceURI(String prefix) {
                String uri = get(prefix);
                if (uri != null) {
                    return uri;
                return XMLConstants.NULL_NS_URI;
            public String getPrefix(String namespaceURI) {
                for (String prefix : keySet()) {
                    if (get(prefix).equals(namespaceURI)) {
                        return prefix;
                return null;
            public Iterator getPrefixes(String namespaceURI) {
                List<String> prefixes = new ArrayList<String>();
                for (String prefix : keySet()) {
                    if (get(prefix).equals(namespaceURI)) {
                        prefixes.add(prefix);
                return prefixes.iterator();
    }To use this class you can do something like this:
    NamespaceContextMap mappings = new NamespaceContextMap();
    mappings.put("itunes", "http://www.itunes.com/DTDs/Podcast-1.0.dtd");
    xPath.setNamespaceContext(mappings);

  • Deadlock in schema validation using XMLBeans

    Hi,
    I am using WLI8.1 SP2 XMLBeans. I have a schema which has a kind of an infinite
    loop. ie I have a complexType element A which has a complexType child element
    B which inturn has a complexType child element of type A with minoccurs="0".
    When I try to validate the incoming XML using XMLBeans generated from the above
    schema, the thread goes into a deadlock and the transaction rollbacks after the
    given timeout period.
    I checked the workshop_debug.log and found the thread gets struck when it calls
    the validate() function of the XMLObject.
    Has anybody faced this error or is it a bug in BEA XMLBeans validate function
    to handle such schema. I tried to validate the same XML using XML SPY and it worked.
    Here is the sample of my schema.
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
    attributeFormDefault="unqualified">
         <xs:element name="ShippingOrderNotification">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="ShippingContainer" type="ShippingContainerType" minOccurs="0"
    maxOccurs="unbounded"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:complexType name="ShippingContainerType">
              <xs:sequence>
                   <xs:element name="SubContainer" minOccurs="0" maxOccurs="unbounded">
                        <xs:complexType>
                             <xs:sequence>
                                  <xs:element name="ShippingContainer" type="ShippingContainerType" minOccurs="0"
    maxOccurs="unbounded"/>
                             </xs:sequence>
                        </xs:complexType>
                   </xs:element>
              </xs:sequence>
         </xs:complexType>
    </xs:schema>

    Please make sure that main xsd uses import or include tag to reference both schema1.xsd and schema2.xsd. If the main xsd does not do it, Pi cannot verify it. Since you package all the files as zip file, also make sure the path for the secondary files are in proper location.
    In short, the import element allows you to use schema components from any schema; the include element allows you to add all the components of an included schema to the containing schema. If the target namespace is same for both then include tag should be good enough. If you don't find one, you might have to use include tag element in the main or parent xsd file.
    Edited by: Baskar Gopal on Jan 31, 2012 5:18 PM

  • Forming XMLs using XML beans

    Hi ,
    I am forming XMLs using XMLBeans whose XSDs been provided.
    The tag values are coming from the database which I am querying.
    and then adding the various tags as per the XSD.
    In the End,I am using the ,doc.toString() where doc is the Document object as per the XSD.
    and then writing it to a file.
    I want to know ,what limitations can this method have or what might be a better way.
    Will there be a restriction on the size of the xml being formed??
    Thanks in Advance

    I modified the code :
    [code]
    Select P.PAT_MRN,
               XMLELEMENT("Patient",
                          (XMLELEMENT("pat_mrn", P.pat_mrn)),
                          (XMLForest(cm_results_o_t(CAST(MULTISET
                                                                    (SELECT O.COMP_NAME AS "ID"
                                                                       FROM oper O
                                                                      WHERE O.ENCOUNTER_ID =
                                                                            E.ENCOUNTER_ID) AS
                                                                    component_list_t)) AS
                                               "Results"))) AS Orderxml
         FROM PATIENT P
         JOIN ENCOUNT E
           ON P.PAT_MRN = E.PAT_MRN
          AND P.PAT_MRN = '63280'
          AND E.ENCOUNTER_ID = 42
    [/code]
    Need the Res_LIST tag to be removed which is coming from object type.

  • How to get an object of choice from XML data using XMLBean?

    I have xml schema and I have generated a jar to represent my schema using XMLBean. I also have few xml data files, these are valid xml for generated schema. Now I want to write a utility which takes xml file as input and returns an object of my choice (Assuming this Object type is available in the jar) as output and vice versa. Some thing like this –
    1. Object getObjectFromXML(File xmldatafile, Class classname)
    xmldatafile = presents the source of XML data
    classname = an object of this class type as output filled from the xml data.
    2. String getXMLStrFromObject(Object)
    Pass Object and get XML as String output
    Any pointer?
    Thanks,

    Hi! Maybe have a look at the documentation for XmlObject.Factory.parse(). It should allow you what you need to do.
    Cheers,
    G.

  • Parsing an xml output of a ws-client using JDOM

    how do i use jdom to parse an output from a web service client,
    ive been using JDev. 10g, was able to create a web service client to consume and return the output in the form of an xml.
    i want to be able to parse the xml doc into variables such that i can insert them into the database.
    is it possible to parse without saving it?
    cheers,
    Shivek Sachdev

    how do i use jdom to parse an output from a web service client,
    ive been using JDev. 10g, was able to create a web service client to consume and return the output in the form of an xml.
    i want to be able to parse the xml doc into variables such that i can insert them into the database.
    is it possible to parse without saving it?
    cheers,
    Shivek Sachdev

  • Need Suggestion on the xml parser to be used in weblogic env.

    Hi All,
    1. I would like to know what is the parser suggested to be used when our application is running in the weblogic env. We have xerces parser already shipped in along with jdk and oracle's xdk parser is also available in the env.
    Kindly let me know what is the suggested one to use?
    2. In one of our applications, jaxp factory (javax.xml.parsers.DocumentBuilderFactory) is explicitly set to xerces's (com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl).
    Now when we changed it to use oracle xdk parser (oracle.xml.jaxp.JXDocumentBuilderFactory), We are running in to issues like 'IllegalArgumentException :not able to set Schema in setAttribute()' as a File Type.
    Previously, we used to set the Schema as File Type when xerces parser is used and that used to work fine.
    Kindly let me know the way which is accepted by both the parsers.
    Thanks
    Rajesh

    Use the default parser.
    By default, WebLogic Server is configured to use the default parser and transformer to parse and transform XML documents. The default parser and transformer are those included in the JDK 5.0.
    The built-in WebLogic Server DOM factory implementation class is com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl.
    The DocumentBuilderFactory.newInstance method returns the built-in parser.
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

Maybe you are looking for

  • Can I have 2 music libraries on the same computer?

    I have an iPod and my wife would like to purchase one aswell. All of my music resides on my desktop. Our tastes in music differ a bit so she would like her own library and I would like mine. If we purchase a new iPod can we have two libraries? Thanks

  • Won't display ANY of my music

    Okay, so my mini works fine one day and ***** the next. When I scroll in my Music, it does not list any artists, albums, songs, etc. It seems as if it erased everything. So, I go to my settings and go to the about column, it lists that I still have 1

  • What is a pocket data?

    i dont know what this? when i try to open radio it says pocket dat is not available or connected? how can i connect it? where can i get this? Solved! Go to Solution.

  • Why does WFM_DB_Transfer generate an error 10803 after functioning well for a few iterations?

    I am outputing a waveform via the WFM_DB_Transfer function, and it functions fine for about the first fifty or so buffers. However afterwards it generates the error 10803. This happened when I had the oldDataStop set to 1 in the WFM_DB_Config. My sit

  • System-provided icons: how to access?

    Mac OS X provides a number of "system-provided icons" (see https://developer.apple.com/library/mac/#documentation/userexperience/Conceptual/AppleHIGuidelines/SystemProvidedIcons/SystemProvidedIcons.html) for use in designing user interfaces. How can