Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Creating valid and well-formed XML-output

Re: Creating valid and well-formed XML-output

From: Maxim Demenko <mdemenko_at_arcor.de>
Date: Wed, 16 Aug 2006 11:56:01 +0200
Message-ID: <44e2ed5b$0$1404$9b4e6d93@newsspool3.arcor-online.net>


willy schrieb:
> I'd like to create a script to generate a valid XML-file based upon the
> contents of a table containing employee information.
> So far, I've come up with the following:
> SELECT SYS_XMLGEN(XMLELEMENT("Medewerker",
> XMLFOREST(Registratienr,
> Voornaam,
> Achternaam,
> Tussenvoegsel,
> Voorletters,
> Geslacht,
> Datum_uit_dienst,
> Gebruikersnaam,
> Email
> )))
> FROM medewerkers
> /
>
> This results into the following XML-file:
>
> <?xml version="1.0"?>
> <Medewerkerslijst>
> <ROW>
> <REGISTRATIENR>123456789</REGISTRATIENR>
> <VOORNAAM>John</VOORNAAM>
> <ACHTERNAAM>Jansen</ACHTERNAAM>
> <VOORLETTERS>J</VOORLETTERS>
> <GESLACHT>M</GESLACHT>
> <GEBRUIKERSNAAM>xxx222</GEBRUIKERSNAAM>
> <EMAIL>john_at_ourcompany.nl</EMAIL>
> </ROW>
> <ROW>
> <REGISTRATIENR>987654321</REGISTRATIENR>
> <VOORNAAM>Pietje</VOORNAAM>
> <ACHTERNAAM>Boer</ACHTERNAAM>
> <TUSSENVOEGSEL>de</TUSSENVOEGSEL>
> <VOORLETTERS>P.</VOORLETTERS>
> <GESLACHT>M</GESLACHT>
> <GEBRUIKERSNAAM>xxx111</GEBRUIKERSNAAM>
> <EMAIL>pietje_at_ourcompany.nl</EMAIL>
> </ROW>
> </Medewerkerslijst>
>
> This is a valid XML-file, but in order for the file to be wellformed as
> well as valid I'll have to change the element <ROW> into <MEDEWERKER>.
> In addition, I'd like to add elements to point to a style sheet, e.g.
> <?xml-stylesheet href="test.xsl" type="text/xsl" ?>, and a reference to
> an XML-schema in the root-element <Medewerkerslijst>.
> I think I ought to achieve this by using the XMLFORMAT.createformat
> statement, but I can't seem to figure it out.
> Any help would be appreciated.
>
> Willy Tadema
>

Maybe this works for you.

   1 SELECT Xmlroot(Xmlconcat(Xmlpi(NAME "xml-stylesheet",'href="test.xsl" type="text/xsl"'),

   2 Xmlelement("Medewerkerslijst",

   3     Xmlattributes('http://www.my.schema' AS "xmlns"),
   4     Xmlagg(Xmlelement("Medewerker",
   5             Xmlforest(Registratienr,
   6                     Voornaam,
   7                     Achternaam,
   8                     Tussenvoegsel,
   9                     Voorletters,
  10                     Geslacht,
  11                     Datum_Uit_Dienst,
  12                     Gebruikersnaam,
  13                     Email))))),

  14 Version '1.0',
  15 Standalone NO VALUE) as xml
  16* FROM Medewerkers

XML


<?xml version="1.0"?>
<?xml-stylesheet href="test.xsl" type="text/xsl"?>
<Medewerkerslijst xmlns="http://www.my.schema">
   <Medewerker>
     <REGISTRATIENR>123456789</REGISTRATIENR>
     <VOORNAAM>John</VOORNAAM>
     <ACHTERNAAM>Jansen</ACHTERNAAM>
     <VOORLETTERS>J</VOORLETTERS>
     <GESLACHT>M</GESLACHT>
     <GEBRUIKERSNAAM>xxx222</GEBRUIKERSNAAM>
     <EMAIL>john_at_ourcompany.nl</EMAIL>

   </Medewerker>
   <Medewerker>
     <REGISTRATIENR>987654321</REGISTRATIENR>
     <VOORNAAM>Pietje</VOORNAAM>
     <ACHTERNAAM>Boer</ACHTERNAAM>
     <TUSSENVOEGSEL>de</TUSSENVOEGSEL>
     <VOORLETTERS>P.</VOORLETTERS>
     <GESLACHT>M</GESLACHT>
     <GEBRUIKERSNAAM>xxx111</GEBRUIKERSNAAM>
     <EMAIL>pietje_at_ourcompany.nl</EMAIL>
   </Medewerker>
</Medewerkerslijst>

Best regards

Maxim Received on Wed Aug 16 2006 - 04:56:01 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US