Validate empty tags using xquery

Hi All,
I have a question regarding xquery flwor exrpession. My scenarion is I need to validate an xml input file wether one of its elements is empty so I created an xquery to validate. However, I receive an error when I try to make an input file that has a repeating element.
Below is my xquery for validating empty tags:
declare namespace cred="http://www.pldt.com.ph/eai/service/component/CreditService/";
declare namespace com="http://www.pldt.com.ph/eai/Common";
declare variable $inputdata as element(cred:PushQuote) external;
let $QuoteNumber := data($inputdata/PushQuote/com:QuoteNumber)
let $AccountNumber := data($inputdata/PushQuote/com:CustomerAccountNumber)
let $QuoteLineItemList := $inputdata/PushQuote/com:LineItemList
for $data in $inputdata
return
if (fn:string-length($QuoteNumber) > 0 and
fn:string-length($AccountNumber) > 0)
then
for $quoteLineItem in $QuoteLineItemList
return
if (fn:string-length(data($quoteLineItem/com:QuoteLineItem/com:LineNumber)) > 0 and
fn:string-length(data($quoteLineItem/com:QuoteLineItem/com:ProductCatalogId)) > 0 and
fn:string-length(data($quoteLineItem/com:QuoteLineItem/com:Product)) > 0 and
fn:string-length(data($quoteLineItem/com:QuoteLineItem/com:Quantity)) > 0 and
fn:string-length(data($quoteLineItem/com:QuoteLineItem/com:Mrc)) > 0 and
fn:string-length(data($quoteLineItem/com:QuoteLineItem/com:Currency)) > 0 and
fn:string-length(data($quoteLineItem/com:QuoteLineItem/com:LastUpdateDate)) > 0 and
fn:string-length(data($quoteLineItem/com:QuoteLineItem/com:LastUpdatedBy)))
then
"0"
else
"1"
else
"1"
Below is my input xml document:
<cred:PushQuote xmlns:com="http://www.pldt.com.ph/eai/Common" xmlns:cred="http://www.pldt.com.ph/eai/service/component/CreditService/">
<PushQuote>
<com:QuoteNumber>ZXCV-233</com:QuoteNumber>
<com:CustomerAccountNumber>1213654889</com:CustomerAccountNumber>
<!--Optional:-->
<com:LineItemList>
*<!--1 or more repetitions:-->*
<com:QuoteLineItem>
<com:LineNumber>3</com:LineNumber>
<com:ProductCatalogId>string</com:ProductCatalogId>
<com:Product>asdf</com:Product>
<com:Quantity>string</com:Quantity>
<com:Mrc>3</com:Mrc>
<com:Currency>USD</com:Currency>
<com:LastUpdateDate>string</com:LastUpdateDate>
<com:LastUpdatedBy>string</com:LastUpdatedBy>
</com:QuoteLineItem>
<com:QuoteLineItem>
<com:LineNumber>3</com:LineNumber>
<com:ProductCatalogId>string</com:ProductCatalogId>
<com:Product>1234</com:Product>
<com:Quantity>string</com:Quantity>
<com:Mrc>3</com:Mrc>
<com:Currency>USD</com:Currency>
<com:LastUpdateDate>string</com:LastUpdateDate>
<com:LastUpdatedBy>string</com:LastUpdatedBy>
</com:QuoteLineItem>
<com:QuoteLineItem>
<com:LineNumber>3</com:LineNumber>
<com:ProductCatalogId>string</com:ProductCatalogId>
<com:Product></com:Product>
<com:Quantity>string</com:Quantity>
<com:Mrc>3</com:Mrc>
<com:Currency>USD</com:Currency>
<com:LastUpdateDate>string</com:LastUpdateDate>
<com:LastUpdatedBy>string</com:LastUpdatedBy>
</com:QuoteLineItem>          
</com:LineItemList>
</PushQuote>
</cred:PushQuote>

atheek1 wrote:
Try this:
<ResultDoc>
for data in $inputData/PushQuote
return
if( put all your if conditions here) then
<result> 1</result>
else
<result>0</result>
</ResultDoc>
This will return a xml :
<ResultDoc>
<result>1</result> <!.. one result per PushQuote in input !>
<result>0</result>
</ResultDoc>yup I've tried that, and now I'm able to get result, my problem now is I can't get the result that is equal to 1 even if I use xpath.
please see my updated code:
declare namespace cred="http://www.pldt.com.ph/eai/service/component/CreditService/";
declare namespace com="http://www.pldt.com.ph/eai/Common";
declare function local:CheckValidation($PushQuote as element(cred:PushQuote))
let $QuoteNumber := data($PushQuote/PushQuote/com:QuoteNumber)
let $AccountNumber := data($PushQuote/PushQuote/com:CustomerAccountNumber)
let $QuoteLineItemList := $PushQuote/PushQuote/com:LineItemList/com:QuoteLineItem
return
<status>
for $QuoteLineItem in $QuoteLineItemList
return
if (fn:string-length(data($QuoteNumber)) > 0 and
fn:string-length(data($AccountNumber)) > 0 and
fn:string-length(data($QuoteLineItem/com:Quantity)) > 0 and
fn:string-length(data($QuoteLineItem/com:Product)) > 0 and
fn:string-length(data($QuoteLineItem/com:Mrc)) > 0 and
fn:string-length(data($QuoteLineItem/com:Currency)) > 0 and
fn:string-length(data($QuoteLineItem/com:LastUpdateDate)) > 0 and
fn:string-length(data($QuoteLineItem/com:LastUpdatedBy)) > 0)
then
<code>0</code>
else
<code>1</code>
</status>
declare variable $PushQuote as element(cred:PushQuote) external;
let $returnValue := local:CheckValidation($PushQuote)
return
$returnValue
$returnValue[code=1]/code
I've tried putting xpath like this to get result = 1 but no luck :)

Similar Messages

  • How to Get and Update properties values from XML tag Using Xquery or PL Sql

    Hi
    I have this tag
    <Solicitud Pais = "1">
    How i can get Pais value?
    How i can update Pais Value?
    Y can use Xquery funtions or PL SQL for this?
    Thak's
    Angel

    How i can get Pais value? ExtractValue
    How i can update Pais Value?UpdateXML
    Y can use Xquery funtions or PL SQL for this?Yes
    Without knowing more about your requirements, where information resides, or even a version of Oracle, that is the best I'll do.

  • How to generate empty tag using XMLForest

    Hi,
    I am creating an XML document using XMLAgg, XMLForest and XMlElement functions.
    At some point I have an XMLForest embedded in the other XMLForest
    XMLForest( e.indicator as "col1",
               e.participant_id as "col2",
      XMLForest( tableAlias.col11 as "address1",
                 tableAlias.col12 as "address2",            
               ) as "items",
    )           and within the last one I have some expressions which are empty, so the XML tags are not generated, however I have to have an empty tags:
    <address2></address2>I tried to replace an expression using "NVL" or "DECODE", but the results were the same.
    I also tried to replace an embedded XMLForest with an XMLElement :
    XMLForest( e.indicator as "col1",
               e.participant_id as "col2",
      *XMLElement("items"*
                 *XMLElement("address1"),*
                 *XMLElement("address2")*
               *) as "items",*)           however it created 2 <items> tags :
        <items>
             <items>
                <address1>value</address1>
                <address2></address2>
             </items>
         </items> I am working with Oracle 11.2.0 db.
    Is there any way to generate an empty tag when using XMLForest function?
    thank you in advance.
    Edited by: user624274 on Apr 3, 2013 8:52 AM
    Edited by: user624274 on Apr 3, 2013 8:53 AM

    Hello Odie_63.
    Your argument is valid, but it does not mean the solution I provided is bad.
    If you are concerned about the size of the result, it is simple, you can use like:
    REPLACE(XMLForest( NVL(e.indicator, '#NULLValue#') as "col1",  NVL(e.participant_id, '#NULLValue#') as "col2").getClobVal(), '#NULLValue#', '')
    According to Oracle documentation, REPLACE is smart and will return a CLOB (not a varchar2) because it changes the type of return according to the type of the first parameter. So you will not have issues with size.
    I believe the first question was related to use the final result to record to a table or send to another system (to use as integration). If it will be used just in a select field, it does not matter if it is not there or if it is there as NULL, the select of the field will always return ''.
    Other hint, I never use xmltype to store on database, because it is not compatible with other databases or integration tools. I use CLOB because it is the natural serialization of the object and I can convert and work with it inside and outside Oracle.
    But that is up to the architect and/or developer. If the system is running only on Oracle and there is no integration, maybe xmltype will save a lot of time in conversions.
    Regards.
    Rodolpho

  • Checking for empty tags using expression builder for XPATH

    I am creating several filters in a mediator for several parallel paths. I am trying to route the mediator to the correct DB adapter based on what tags are empty in the incoming XML. The XML has 1 required tag and 3 optional. So for the expression, I am using the expression builder to load the tag name then putting either [text()] or [not(text())] immediately after each tag with an "and" in between for the 3 optional elements. The problem I am having is they always return false. For example, if I enter a value for an optional tag and put [text()] after it, it evaluates to false. What is the correct way to check if an element has text or not?
    Thanks in advance!

    Hi,
    Its not recognizing the getVariableData func... instead try this:
    string-length(xpath)>0
    ex: string-length($in.body/imp1:manoj/imp1:C1)>0
    It works... Happy deploying ... :)

  • Adding an empty tag with jaxp

    hi,
    I'm trying to add an empty tag using jaxp.
    The code i'm using is:
    Element test = document.createElement("test");
    root.appendChild(test);
    The result of this is this xml-string:
    <root>
    <test></test>
    What I want as result is somthing like this:
    <root>
    <test/>
    Can anyone tell me what I have to do?
    thanks,
    Hans

    What I want as result is somthing like this:
    <root>
    <test/>
    Can anyone tell me what I have to do?hmm; for my latest project i made my own class to do all the xml - it's quite basic (ie; easy to implement) and doesn't do any validation, it basically has 3 methods: set, toString & getXML(). i'm not sure this is what you're looking for, but if you wish i could post the source code or email it to you.
    cheers,
    //adrian.

  • Remove Empty XML Tags using module parameters

    Hi All,
    In my lanscape I have two PI Systems.
    My scenario is an IDOC reaches 1st PI system gets converted into an EDIFACT and then goes to the 2nd PI and from there it gets routed to the respective AS2 Party.
    I am using SOAP to pass message between the PI systems and B2B Toolkit's AS2 Adapter for the communication with AS2 party.
    The issue is when the message is getting converted from IDOC to EDIFACT there are a few feilds with occurence 1..1 and due to these fields i get an empty XML tag at the output. These empty XML tags give me an error in the B2B Toolkit's AS2 Adapter Receiver Channel
    I cannot change the occurence in the structure of the EDIFACT nor can I use an XSLT mapping to remove empty tags before the message reaches the Communication Channel.
    I want to know if there are any module parameters which i can use either in SOAP Channel or the AS2 Channel to remove the XML Tags.

    Hi Muni,
    "1..1 means, you must send some values for that fields. try to find out why these are not getting any values."
    This empty tag is expected. Before using B2B Toolkit's AS2 Adapter we used to use Seeburger's AS2 Adpater and the message used to get executed successfully with these empty tags.The issue is coming only when we are using B2B Toolkit's AS2 Adapter.
    "if you want to stop sending(the fields which are not needed in target) you can you can disable the fields in the message mapping."
    I cannot disable the feild in the mapping as some other message may use this field.
    Thanks,
    Farhaan

  • How to append the declaration tags to generated xml using Xquery

    Hi,
      How to append the declaration tags to generated xml using Xquery.generated XML is like
    <ROOT>
      <CHILD1></CHILD1>
      <CHILD2></CHILD2>
    </ROOT>
    Here I want to append the <?xml version="1.0" encoding="ISO-8859-1"?> and the result xml should be
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <ROOT>
      <CHILD1></CHILD1>
      <CHILD2></CHILD2>
    </ROOT>
    Can anybody help to do this.
    Thanks
    Mani

    First assign this element to a temp variable
    <ROOT>
      <CHILD1></CHILD1>
      <CHILD2></CHILD2>
    </ROOT>
    Now in XQuery expression create a new variable
    <?xml version="1.0" encoding="ISO-8859-1"?>
    $temp

  • How can I control creation of empty tags when using ora:view syntax?

    I'm using XMLQuery and ora:view syntax to create xml resources in the database but I'd like to be able to prevent the creation of empty tags for null values in the table.
    CREATE OR REPLACE PROCEDURE proc_ctsi_build is
    XMLdoc XMLType;
    BEGIN
    DBMS_XDB.deleteResource('/public/CTSI/ctsi_phsall_rpt1.xml',1);
    SELECT XMLQuery(
    '<Progress_Report>
    <Personnel_Roster>
    {for $c in ora:view("CTSI_INVEST_SOURCE_V")
        let $username  := $c/ROW/COMMONS_USERNAME/text(),
    $expertise  := $c/ROW/AREA_OF_EXPERTISE/text()
         return
      <Investigator>
       <Commons_Username>{$username}</Commons_Username>
    <Area_of_Expertise>{$expertise}</Area_of_Expertise>
    </Investigator>}
    </Personnel_Roster>
    </Progress_Report>'
    RETURNING CONTENT) INTO XMLdoc FROM DUAL;
    IF(DBMS_XDB.CREATERESOURCE('/public/CTSI/ctsi_phsall_rpt1.xml', XMLdoc)) THEN
    DBMS_OUTPUT.PUT_LINE('Resource is created');
    ELSE
    DBMS_OUTPUT.PUT_LINE('Cannot create resource');
    END IF;
    COMMIT;
    END;
    In this example how can I prevent getting <Area_of_Expertise/> in my output when AREA_OF_EXPERTISE is null in the table?
    Thanks

    Hi,
    you can use if else conditions.
    {if ($expertise) then
    <Area_of_Expertise>{$expertise}</Area_of_Expertise>
    else ()}
    **not tested**
    Ants
    Message was edited by:
    Ants Hindpere

  • Specifying empty tag style

    Hi all. I'm using dbms_xmlquery.useNullAttributeIndicator, and for a reason I'd rather not go into I need the tags to be separate open-close tags (<tag></tag>) instead of the more elegant <tag/> tag. I'd also like to suppress the NULL="TRUE" attribute if possible. I'm open to changing our routine to use DBMS_XMLGEN if it helps in the above. Many thanks in advance for your help.

    Hi,
    With DBMS_XMLGEN, you can get rid of the NULL attribute, but empty tags will appear in the short form :
    SQL> set serveroutput on
    SQL> DECLARE
      2    ctx    dbms_xmlgen.ctxHandle;
      3    sqlstr varchar2(4000) := 'SELECT * FROM scott.emp WHERE rownum = 1';
      4    res    clob;
      5  BEGIN
      6    ctx := dbms_xmlgen.newContext(sqlstr);
      7    dbms_xmlgen.setNullHandling(ctx, dbms_xmlgen.EMPTY_TAG);
      8    res := dbms_xmlgen.getXML(ctx);
      9    dbms_xmlgen.closeContext(ctx);
    10    dbms_output.put_line(res);
    11  END;
    12  /
    <?xml version="1.0"?>
    <ROWSET>
    <ROW>
      <EMPNO>7369</EMPNO>
      <ENAME>SMITH</ENAME>
      <JOB>CLERK</JOB>
      <MGR>7902</MGR>
      <HIREDATE>17/12/80</HIREDATE>
      <SAL>800</SAL>
      <COMM/>
      <DEPTNO>20</DEPTNO>
    </ROW>
    </ROWSET>
    PL/SQL procedure successfully completed
    On the latest release (11.2), and only for particular cases, you might be able to do what you want with XQuery.
    See § Oracle XQuery Extension-Expression Pragmas on this page :
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e16659/xdb_xquery.htm
    Here's also an example :
    SELECT XMLSerialize(
    document
    XMLQuery(
      '(#ora:view_on_null empty #)
       <ROWSET>
        for $i in fn:collection("oradb:/SCOTT/EMP")/ROW
        where $i/EMPNO = 7566
        return $i
       </ROWSET>
      returning content
    as clob
    FROM dual;
    <ROWSET><ROW><EMPNO>7566</EMPNO><ENAME>JONES</ENAME><JOB>MANAGER</JOB><MGR>7839</MGR><HIREDATE>1981-04-02</HIREDATE><SAL>2975</SAL><COMM></COMM><DEPTNO>20</DEPTNO></ROW></ROWSET>

  • Empty Collections and Empty Tags

    It seems that empty collections from a cast or cursor result in an empty tag. For example, the following sql:select work.work_id medlineid,
    cursor(
    select
    databankname,
    db.accessionnumberlist_ref.accessionnumberlist accessionnumberlist
    from table(dbl.databanks) db
    order by databankname) databanklist,
    cast( multiset (
    select chemical_t(
    wrkchm.cas_registry_number,
    wrkchm.term)
    from work_chemicals wrkchm
    where wrkchm.work_id=work.work_id
    order by wrkchm.term) as chemicals_t) chemicallist
    from
    works work,
    databanklist_t_v dbl
    where
    work.work_id = 96264942
    and work.work_id = dbl.work_id(+)results in the following XML:<medlinecitationset>
    <medlinecitation num="1">
    <medlineid>96264942</medlineid>
    <databanklist/>
    <chemicallist/>
    </medlinecitation>
    </medlinecitationset>Is there a way to not have these empty tags appear?
    Thanks! -- John.
    null

    David, this is about understanding the use of, and differencies between tags and collections. This is a bit hard for many new users.
    First of all searching for collections and tags can *not* be done simultaneously. You can either work with one collection only, or you can search for pictures with one or more tags.
    Next collections should be used as either temporary work sets or for special occasions like specific vacations, trips or birthdays, e.g. "Anna 5 years". You say you have a collection named "Churches". I think would have made a TAG called "Churches" instead, because a tag is for general searches that can be combined. On the other hand I might have made a collection called "Church visits July 2005" or "Summer vacation 2005" or the like.
    Another difference is that pictures in a collection can be sorted manually by drag & drop, while pictures found via tags always are shown in the order chosen in the Photo Browser Arrangement box shown bottom left in the Organizer.

  • Is there a way to modify the style sheet so that it transforms an XML document with empty tags as tag / ?

    I have extracted some code from codeproject to
    reindent an XML document. Does anyone know how I can modify the stylesheet to make it so that the transform of an XML file will result in empty tags showing up as <tag /> instead of <tag></tag>?
    // http://www.codeproject.com/Articles/43309/How-to-create-a-simple-XML-file-using-MSXML-in-C
    MSXML2::IXMLDOMDocumentPtr FormatDOMDocument(MSXML2::IXMLDOMDocumentPtr pDoc)
    LPCSTR const static szStyleSheet =
    R"!(<?xml version="1.0" encoding="utf-8"?>)!"
    R"!(<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">)!"
    R"!( <xsl:output method="xml" indent="yes"/>)!"
    R"!( <xsl:template match="@* | node()">)!"
    R"!( <xsl:copy>)!"
    R"!( <xsl:apply-templates select="@* | node()"/>)!"
    R"!( </xsl:copy>)!"
    R"!( </xsl:template>)!"
    R"!(</xsl:stylesheet>)!";
    MSXML2::IXMLDOMDocumentPtr pXmlStyleSheet;
    pXmlStyleSheet.CreateInstance(__uuidof(MSXML2::DOMDocument60));
    pXmlStyleSheet->loadXML(szStyleSheet);
    MSXML2::IXMLDOMDocumentPtr pXmlFormattedDoc;
    pXmlFormattedDoc.CreateInstance(__uuidof(MSXML2::DOMDocument60));
    CComPtr<IDispatch> pDispatch;
    HRESULT hr = pXmlFormattedDoc->QueryInterface(IID_IDispatch, (void**)&pDispatch);
    if (SUCCEEDED(hr))
    _variant_t vtOutObject;
    vtOutObject.vt = VT_DISPATCH;
    vtOutObject.pdispVal = pDispatch;
    vtOutObject.pdispVal->AddRef();
    hr = pDoc->transformNodeToObject(pXmlStyleSheet, vtOutObject);
    //By default it is writing the encoding = UTF-16. Let us change the encoding to UTF-8
    // <?xml version="1.0" encoding="UTF-8"?>
    MSXML2::IXMLDOMNodePtr pXMLFirstChild = pXmlFormattedDoc->GetfirstChild();
    // A map of the a attributes (vesrsion, encoding) values (1.0, UTF-8) pair
    MSXML2::IXMLDOMNamedNodeMapPtr pXMLAttributeMap = pXMLFirstChild->Getattributes();
    MSXML2::IXMLDOMNodePtr pXMLEncodNode = pXMLAttributeMap->getNamedItem(_T("encoding"));
    pXMLEncodNode->PutnodeValue(_T("UTF-8")); //encoding = UTF-8
    return pXmlFormattedDoc;
    Or, if there is some other method for reindenting a MSXML2::IXMLDOMDocumentPtr object where I can specify how I want empty tags to be stored, that would be great too.  However, I don't want it to lose its status of an MSXML2::IXMLDOMDocumentPtr object.
     I.e. I would like to still perform operations on the result as if it was still an MSXML2::IXMLDOMDocumentPtr object.
    Thanks,
    A
    Adrian

    If anyone is interested, I got an answer on StackOverflow
    here.
    Adrian

  • XML: empty tag issue

    I use Transformer class to convert xml Document into string representation:
    StringWriter sw = new StringWriter();     
    TransformerFactory transFactory = TransformerFactory.newInstance();
    Transformer transformer = transFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
    transformer.setParameter(OutputKeys.ENCODING, "UTF-8");
    transformer.transform(new DOMSource(doc), new StreamResult(sw));
    but if the content of the tag is empty, the output is in this format: <tag />. Can someone know how to get the following format instead: <tag></tag>?
    Thanks,

    I suggest that you write a specific function to translate the string with auto-close tags to empty tags instead. It is not very difficult to do and you can look at [http://sourceforge.net/projects/light-html2xml|http://sourceforge.net/projects/light-html2xml] where you will find a similar java function to convert HTML to well-formed XML.

  • Not getting empty tags in XML output

    Hello,
    I am using DBMS_XMLQuery.getXML function and cusor function in my select statement to generate XML documents. If the column value is null, the XML document is not generating a empty tag. How do I generate empty tags?
    My query is :-
    SELECT
    MSG_NAME ,MSG_DATE, BATCH_ID,
    cursor (SELECT ACTION_CODE,PART_NUMBER,
    ITEM_DESCRIPTION,ITEM_STATUS
    UOM,CONVERSIONS,INSPECTION_FLG
    FROM ITEM_OUT ITEM
    WHERE ITEM.BATCH_ID= ECF.MSG_BATCH_ID
    ) as item_header
    FROM FILE_CONTROL ECF
    null

    You need to set the option to use a null indicator. By default, null values omit their elements. With the null indicator, they are included as empty elements with a NULL="Y" attribute flag.

  • How to remove empty tag.

    Hi,
    I have a scenario IDOC-XI-JDBC
    From IDOC we are using change pointers and when something has been changed then those fields are being sent out but other few empty fields were coming out and to avoid that I used mapWithDefault to avoid the empty tags as  target system used to error out.
    But now when any field is empty coming from change pointer is also being caught in mapWithDefault....whereas it is expected to send blank.
    Can anyone of you suggest any solution.
    Regards
    Ria

    Hi Ria,
    You can use if without else and check the field exist or not in the source and then map it to target.
    This is a bit tricky & if you dont feel comfortable with it, then use advanced UDF, and explicitely check ResultList.SUPPRESS object and remove it in UDF and form an output stream.
    You can use any of the two.
    Regards,
    Shri.
    <removed by moderator>
    Edited by: Mike Pokraka on Jul 28, 2008 5:05 PM

  • Marshalling HashMap with JAXB 2.0 - empty tags & ill schema

    Hi all,
    I expected JAXB 2.0 to be capable to handle basic classes like HashMap, but it does not look so. I have two classes: SimpleNegotiationManager which has a property HashMap in which are stored the instances of SimpleInitiatedConversation:
    package xml;
    import javax.xml.bind.annotation.*;
    import java.util.HashMap;
    @XmlAccessorType(AccessType.FIELD)
    @XmlRootElement
    public class SimpleNegotiationManager {
        @XmlElement
        protected HashMap<String, SimpleInitiatedConversation> initiatedConversations;
        public SimpleNegotiationManager() {
        public HashMap<String, SimpleInitiatedConversation> getInitiatedConversations() {
            if (initiatedConversations == null) {
                initiatedConversations = new HashMap();
            return initiatedConversations;
        public void setInitiatedConversations(HashMap<String, SimpleInitiatedConversation> initiatedConversations) {
            this.initiatedConversations = initiatedConversations;
    }and
    package xml;
    import javax.xml.bind.annotation.*;
    import java.util.ArrayList;
    import java.util.List;
    @XmlAccessorType(AccessType.FIELD)
    @XmlType
    public class SimpleInitiatedConversation {
        @XmlElement
        protected List<String> messages;
        protected String conversationID;
        protected int protocolState;
        public SimpleInitiatedConversation() {
        public List<String> getMessages() {
            if (messages == null) {
                messages = new ArrayList();
            return messages;
        public void setMessages(List<String> messages) {
            this.messages = messages;
        public int getProtocolState() {
            return protocolState;
        public void setProtocolState(int protocolState) {
            this.protocolState = protocolState;
        public String getConversationID() {
            return conversationID;
        public void setConversationID(String conversationID) {
            this.conversationID = conversationID;
    }When I marshalled SimpleNegotiationManager while the HashMap was filled with several <String,SimpleInitiatedConversation> entries, in the output were empty tags initiatedConversations:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <simpleNegotiationManager>
      <initiatedConversations>
      </initiatedConversations>
    </simpleNegotiationManager>When I used schemagen to generate a schema, it produced:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:complexType name="simpleInitiatedConversation">
        <xs:sequence>
          <xs:element name="messages" type="xs:string" maxOccurs="unbounded" minOccurs="0"/>
          <xs:element name="conversationID" type="xs:string" minOccurs="0"/>
          <xs:element name="protocolState" type="xs:int"/>
        </xs:sequence>
      </xs:complexType>
      <xs:element name="simpleNegotiationManager" type="simpleNegotiationManager"/>
      <xs:complexType name="simpleNegotiationManager">
        <xs:sequence>
          <xs:element name="initiatedConversations" type="hashMap" minOccurs="0"/>
        </xs:sequence>
      </xs:complexType>
      <xs:complexType name="hashMap">
        <xs:complexContent>
          <xs:extension base="abstractMap">
            <xs:sequence/>
          </xs:extension>
        </xs:complexContent>
      </xs:complexType>
      <xs:complexType name="abstractMap" abstract="true"/>
    </xs:schema>Particularly the description of HashMap seems ill - there is not specified that the HashMap has keys String and values SimpleInitiatedConversation.
    Unfortunatelly, the j2s-xmlAdapter-field example available with JAXB 2.0 is more complicated than I need. I just need to store/load HashMap into/from XML and I do not care what it looks like. Is it possible to avoid extending XmlJavaTypeAdaptor for a simple storing a HashMap into XML? Perhaps I use improper annotations in the source code, but I cannot get it working. Any clue?

    Ok i figured out one way of doing this by using some classes from JAXP...
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema s = null;
    try{
        s = sf.newSchema(new File("Sources/schema/test.xsd"));                    
    }catch(Exception e){
        System.err.println("Exception e: " + e.getMessage());
    marshaller.setSchema(s);
    //MyValidationHandler class implements the ValidationEventHandler interface
    MyValidationHandler gv = new MyValidationHandler();
    marshaller.setEventHandler(gv);If anyone has something to add let me know!!

Maybe you are looking for

  • Old data capture

    Is there any option to capture old data from tally 7.2 to Sap B1.

  • What happened to share slideshow to iDVD option?

    What happened to the "share slideshow to iDVD" option?  Anyone know a fix?

  • Scroll stop to work on application sporadically

    Hello, I have some very strange bug on my new mac book air (2013 max model). Scroll is stop working on browser or xcode randmly. By some reason while I am using either xcode or browser sporadicly scroll stop to work. Application is stil working, you

  • How to use inner class in axis2 in java?

    Hi, Iam very new in axis2. My language is java. What iam trying to do is, i need to create a xml format for the clients to send data to server using axis2 service. My demo xml format is, <test1> <test2> <test3> <test4></test4> <test5></test5> </test3

  • Is it just me, or is this happening to all of us? (READ)

    See i had the first iphone and i notice a couple of things that were bothering me- such as - iphone will always go back to home screen when using the main applications(safari,Weather,Maps etc) for no reason, later i realize the bug was fixed Now i pu