mevada.yogesh
mevada.yogesh

Reputation: 1128

Java xml creation with JDOM/XML

I have an problem in creating xml with the

    <c:condition>
        <a:condition>
            <fieldName>fieldName</fieldName>
            <fieldTest>fieldTest</fieldTest>
            <fieldValues>
                <fieldValue>fieldValue</fieldValue>
            </fieldValues>
        </a:condition>
        <operator>operator</operator>
        <a:condition>
            <fieldName>fieldName</fieldName>
            <fieldTest>fieldTest</fieldTest>
            <fieldValues>
                <fieldValue>fieldValue</fieldValue>
            </fieldValues>
        </a:condition>
    </c:condition>

Above is the xml tag given to me.

I need to create this tag using the JDOM/XML in java.

So I am using

Element complexCondition = new Element("c:condition");

code to create "c:condition" tag.

But I am getting error

org.jdom.IllegalNameException: The name "c:condition" is not legal for JDOM/XML elements: Element names cannot contain colons.

So don't have any idea what is going wrong. As I am new to the xml's and JDOM. Please help me out with this issue.

Upvotes: 2

Views: 1743

Answers (1)

Kent
Kent

Reputation: 195059

c: 

is a namespace prefix. you should create your element with namespace. check the constructor :

Element(java.lang.String name, java.lang.String prefix, java.lang.String uri)
  Creates a new element with the supplied (local) name and a namespace given by the supplied prefix and URI combination.

Upvotes: 5

Related Questions