Parsing an XML and its respective XSD

Asked

Viewed 228 times

2

Precise parse a WADL manually and create an XML with specifications I have here.

Example:

-> Yahoosearch.wadl file

[...]

<application
* xmlns:yn="urn:yahoo:yn" *
>
  <grammars>
    <include 
      href="NewsSearchResponse.xsd"/>
    <include
      href="NewsSearchError.xsd"/>
  </grammars>

[...]

<method name="GET" id="search">
        <request> 
// Aqui há uma requisição com um paramêtro, 
// eu preciso descrever esse parametro no xml posteriormente criado, até aqui OK, dou um jeito
          <param name="appid" type="xsd:string" 
            style="query" required="true"/>
        </request>
        <response status="200"> 
// Aqui há uma resposta do tipo xml,
// aonde o tipo do objeto no conteúdo é um ResultSet,
// que está sendo referenciado lá em cima e descrito logo abaixo
          <representation mediaType="application/xml"
            element="yn:ResultSet"/>
        </response>
</method>

-> Newssearchresponse.xsd archive:

[...]

<!-- Preciso inserir esse cara de uma forma mais descritiva no novo XML,
ou seja, preciso parsear esse XSD, existe uma API para facilitar isso, se não tenho que ir pegando nó por nó e ir construindo um elemento ? -->

  <xs:complexType name="ResultType">
<xs:sequence>
  <xs:element name="Title" type="xs:string"/>
  <xs:element name="Summary" type="xs:string"/>
  <xs:element name="Url" type="xs:string"/>
  <xs:element name="ClickUrl" type="xs:string"/>
  <xs:element name="NewsSource" type="xs:string"/>
  <xs:element name="NewsSourceUrl" type="xs:string"/>
  <xs:element name="Language" type="xs:string"/>
  <xs:element name="PublishDate" type="xs:string"/>
  <xs:element name="ModificationDate" type="xs:string" minOccurs="0"/>
  <xs:element name="Thumbnail" type="ImageType" minOccurs="0"/>
</xs:sequence>

[...]

What API suggest me to use for the above case and suggestions on how to do?

  • 1

    Have you ever looked at http://xstream.codehaus.org/ ? .

  • So, what I realized is that I need to assemble a class that will receive the output of XSD, only that my program will receive several different WADL and with different XSD, ie I do not know the output. Can you answer me if it’s possible to do this with XSTREAM or JAXB?

  • 1

    A perfectly suitable translation for parse is analyze or interpret.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.