Validate XML string against XSD by using Jaxen

View: New views
3 Messages — Rating Filter:   Alert me  

Validate XML string against XSD by using Jaxen

by Rajeevr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Jaxen Users,

I have two basic questions about Jaxen:

Q1. I need to validate a string which contains the data in XML format against a given XSD file by using Jaxen. How this can be done?

XML string can be like this:
<?xml version="1.0"?>
<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="dictionary.xsd">
        <!-- dictionary_invalid_xsd.xml
                Copyright (c) 2002 by Dr. Herong Yang
        -->
        <word acronym="yes">
                <name>XML</name>
                <definition reference="Herong's Notes">
                        eXtensible Markup Language.
                </definition>
                <update date="2003-23-12" />
        </word>
        <word symbol="true">
                <name></name>
                <definition>
                        Mathematical symbol representing the "less than" logical
                        operation, like: 12.
                </definition>
                <definition>
                        Reserved symbol in XML representing the beginning of tags,
                        like:
                        <![CDATA[<p>Hello world!</p>]]></definition>
                <update />
        </word>
        <word symbol="false" acronym="false">
                <name>extensible</name>
                <definition>Capable of being extended.</definition>
        </word>
</dictionary>

XSD is like this:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:element name="dictionary" type="dictionaryType"/>
        <xsd:complexType name="dictionaryType">
                <xsd:sequence>
                        <xsd:element name="word" type="wordType" maxOccurs="unbounded"/>
                </xsd:sequence>
        </xsd:complexType>
        <xsd:complexType name="wordType">
                <xsd:sequence>
                        <xsd:element name="name" type="xsd:string"/>
                        <xsd:element name="definition" type="definitionType" maxOccurs="unbounded"/>
                        <xsd:element name="update" type="updateType" minOccurs="0"/>
                </xsd:sequence>
                <xsd:attribute name="acronym" type="xsd:boolean" use="optional"/>
                <xsd:attribute name="symbol" type="xsd:boolean" use="optional"/>
        </xsd:complexType>
        <xsd:complexType name="definitionType" mixed="true">
                <xsd:attribute name="reference" type="xsd:string"/>
        </xsd:complexType>
        <xsd:complexType name="updateType">
                <xsd:attribute name="date">
                        <xsd:simpleType>
                                <xsd:restriction base="xsd:string">
                                        <xsd:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}"/>
                                </xsd:restriction>
                        </xsd:simpleType>
                </xsd:attribute>
        </xsd:complexType>
</xsd:schema>

Q2. I had done this validation with Xerces. Please also suggest me which methodology is the better one -Jaxen or Xerces?

Regards,
Rajeev Ranjan

Re: Validate XML string against XSD by using Jaxen

by Jacob Kjome :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I'm not sure you'll get much response here until you indicate what your
question has to do with XPath, which is what Jaxen implements?

Jake

On Thu, 14 May 2009 06:54:55 -0700 (PDT)
  Rajeevr <rajeevr@...> wrote:

>
> Hi Jaxen Users,
>
> I have two basic questions about Jaxen:
>
> Q1. I need to validate a string which contains the data in XML format
> against a given XSD file by using Jaxen. How this can be done?
>
> XML string can be like this:
> <?xml version="1.0"?>
> <dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="dictionary.xsd">
> <!-- dictionary_invalid_xsd.xml
> Copyright (c) 2002 by Dr. Herong Yang
> -->
> <word acronym="yes">
> <name>XML</name>
> <definition reference="Herong's Notes">
> eXtensible Markup Language.
> </definition>
> <update date="2003-23-12" />
> </word>
> <word symbol="true">
> <name></name>
> <definition>
> Mathematical symbol representing the "less than" logical
> operation, like: 12.
> </definition>
> <definition>
> Reserved symbol in XML representing the beginning of tags,
> like:
> <![CDATA[<p>Hello world!</p>]]></definition>
> <update />
> </word>
> <word symbol="false" acronym="false">
> <name>extensible</name>
> <definition>Capable of being extended.</definition>
> </word>
> </dictionary>
>
> XSD is like this:
> <?xml version="1.0"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:element name="dictionary" type="dictionaryType"/>
> <xsd:complexType name="dictionaryType">
> <xsd:sequence>
> <xsd:element name="word" type="wordType" maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
> <xsd:complexType name="wordType">
> <xsd:sequence>
> <xsd:element name="name" type="xsd:string"/>
> <xsd:element name="definition" type="definitionType"
> maxOccurs="unbounded"/>
> <xsd:element name="update" type="updateType" minOccurs="0"/>
> </xsd:sequence>
> <xsd:attribute name="acronym" type="xsd:boolean" use="optional"/>
> <xsd:attribute name="symbol" type="xsd:boolean" use="optional"/>
> </xsd:complexType>
> <xsd:complexType name="definitionType" mixed="true">
> <xsd:attribute name="reference" type="xsd:string"/>
> </xsd:complexType>
> <xsd:complexType name="updateType">
> <xsd:attribute name="date">
> <xsd:simpleType>
> <xsd:restriction base="xsd:string">
> <xsd:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}"/>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:attribute>
> </xsd:complexType>
> </xsd:schema>
>
> Q2. I had done this validation with Xerces. Please also suggest me which
> methodology is the better one -Jaxen or Xerces?
>
> Regards,
> Rajeev Ranjan
>
> --
> View this message in context:
>http://www.nabble.com/Validate-XML-string-against-XSD-by-using-Jaxen-tp23541047p23541047.html
> Sent from the jaxen - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Validate XML string against XSD by using Jaxen

by Elliotte Rusty Harold-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, May 14, 2009 at 6:54 AM, Rajeevr <rajeevr@...> wrote:
>
> Hi Jaxen Users,
>
> I have two basic questions about Jaxen:
>
> Q1. I need to validate a string which contains the data in XML format
> against a given XSD file by using Jaxen. How this can be done?
>

It can't. That's not what Jaxen does. Try javax.xml.validation instead.

http://www.ibm.com/developerworks/xml/library/x-javaxmlvalidapi.html

--
Elliotte Rusty Harold
elharo@...

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email