XML with attributes?

Hello
I've got a table XYZ with the fields ABC and DEF. I want Oracle XE database to give me the following XML back:
<ROWSET>
<ROW ABC="..." DEF="..."/>
<ROW ABC="..." DEF="..."/>
</ROWSET>
the fields as attributes. I know only how to get XML with elements but I need xml attributes. Does anybody know how this works with ODP.NET? I use the XmlCommandType property, r=ExecuteXmlReader() function and "doc.load(r)". In the past I got XML with attributes using Oracle9i R2, OO4O and MS Visual Basic 6. I set a property for each column.
Regards
Marcus Warm
(Germany)
[Oracle 10g Express Edition R2, Visual Studio 2005 VB, ADO.NET 2.0, Windows
XP]
<<also posted in de.comp.datenbanken.misc>>

Hi
In this case you have to change your Source structure and map the attrbute values to target and in receiver channel you can perform your content conversion.
Regards
Ramg
Edited by: Ramkumar Ganesh on Apr 28, 2010 11:09 PM

Similar Messages

  • How to write XML with attributes to a table in Oracle?

    I tried to find solutions over the internet. Some of the stuff I looked at:https://forums.oracle.com/thread/2182669 http://www.club-oracle.com/forums/how-to-insert-data-from-xml-to-table-t2845/
    In all these cases, the solution considers XML structure with only nodes and child nodes but not attributes. In fact, one of the solutions suggests transforming the XML into a canonical form with only nodes w/o attributes.
    This is a sample of xml structure I am working with:
    Sample XML
    <rep type="P" title="P List"> <as> <a id="3" /> <a id="4" /> </as> </rep>
    I am working with oracle client 11.2 and SQL developer
    My question is: how to write XML data into a table with attributes also as column values, beside the nodes?

    My question is: how to write XML data into a table with attributes also as column values, beside the nodes
    The question you should be asking is : "how do I access attributes in the XPath language?"
    and the answer to that is easily found in any XPath tutorial you may find over the Internet, it is not related to Oracle in particular.
    Short answer : you use an "attribute::" axis before the attribute name, or more commonly a "@", e.g. @type, @id etc.
    Using the method described in the first link, something like this will extract the root attributes :
    SELECT x.*
    FROM XMLTable(
           '/rep'
           passing <xmltype variable/column goes here>
           columns type  varchar2(1)  path '@type'
                 , title varchar2(30) path '@title'
    ) x ;
    For deeper levels, use additional XMLTable calls as described in the mentioned post.

  • XML with attributes 2 CSV with file adapter

    Hi,
    I have used this [link|http://help.sap.com/saphelp_nw04/Helpdata/EN/24/4cad3baabd4737bab64d0201bc0c6c/content.htm] to convert a xml file to a csv file. That works fine so far as long as my source file is like this:
    <root>
    <tag>
    <element1>
    <element2>
    </tag>
    </root>
    But what can I do if I have it like this?
    <root>
    <tag element1="something" element2="nothing" ...>
    </tag>
    </root>
    With my current settings in my file receiver channel the attributes in this example element1, element2 are not being postet in the csv file and I have no idea how to do this. The link from above does not mention anything like this. Is it possible, at all?
    Best regards.
    Oliver.

    Hi
    In this case you have to change your Source structure and map the attrbute values to target and in receiver channel you can perform your content conversion.
    Regards
    Ramg
    Edited by: Ramkumar Ganesh on Apr 28, 2010 11:09 PM

  • Generating XML with attributes using XSU

    Oracle document claims if the sql is:
    select empno as @empno from employee
    Using XSU to generate XML will produce and XML document with EMPNO as an attribute instead of element name. But this does not seem to work. There is an exception:
    <ERROR>oracle.xml.sql.OracleXMLSQLException: Character '&' is not allowed in an XML tag name.</ERROR
    Is there anything wrong or is there a work around

    Oracle document claims if the sql is:
    select empno as @empno from employee
    Using XSU to generate XML will produce and XML document with EMPNO as an attribute instead of element name. But this does not seem to work. There is an exception:
    <ERROR>oracle.xml.sql.OracleXMLSQLException: Character '&' is not allowed in an XML tag name.</ERROR
    Is there anything wrong or is there a work around

  • Printing XML with attributes

    Hi,
    I wrote some code to generate DOM trees, and some more code to print a tree as a string.
    But my the string loses attributes - i.e. all tags come out without attributes. And I am not sure why....
    public static String getStringXml(Document xmlDoc)
              //Output the XML to string
              TransformerFactory fac = TransformerFactory.newInstance();
              Transformer transformer = null;
              StringWriter writer = new StringWriter();
              try
                   transformer = fac.newTransformer();
                   transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
                   StreamResult result = new StreamResult(writer );
                   DOMSource source = new DOMSource(xmlDoc);
                   transformer.transform(source, result);
              catch (TransformerConfigurationException e)
                   e.printStackTrace();
              catch (TransformerException e)
                   e.printStackTrace();
              return writer.toString();
         }

    It is possible I am doing something wrong when adding attriubtes:
    Element myElement = xmlDoc.createElement("myElement");
    myElement.setAttribute("id", "first");

  • Relational output from XML with attributes

    I'm using a 10g
    I have this XML.
    <items>
    <item name="Book" price="12" itemnumber="230" quantity="57" detail="Oracle book" company="Oracle" />
    <item name="Book" price="23" itemnumber="244" quantity="7" detail="XML book" company="Oracle" />
    </items>
    I want the following relational output:
    name price itemnumber quantity detail company
    Book 12 230 57 Oracle book Oracle
    Book 23 244 7 XML book Oracle
    I am new to this xml stuff and would appreciate any help.
    Thanks!

    You can solve this via xmltable (>= V. 10.2) or the use of a table(xmlsequence(extract())) contruct (<= V. 10.1 <<) or, for instance, via XQuery (>= V. 10.2).

  • Issue with working on a webservice that has  xml elements with attributes

    This is  a branchout of Thread: Some more complex sample of invokin WS needed_
    We are working on a project that involves a outbound SALT Web service call that includes complex elements with attributes..We are looking for options of how to use FML API's to pass these attribute values from the application code.
    We opened a ticket with oracle where we were suggested to frame the entire xml and pass the xml using the FML32 of the complex element. But when we framed the xml for Service and put the entire XML which includes the attributes using the FML ID of Service.
    Please find a sample Schema and XML similar to the one we are working on...its associated code
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
         <xs:element name="Service" type="Service_Type" nillable="true">
              <xs:annotation>
                   <xs:documentation>Comment describing your root element</xs:documentation>
              </xs:annotation>
         </xs:element>
         <xs:complexType name="Service_Type">
              <xs:sequence>
                   <xs:element name="DateTime" type="xs:dateTime" nillable="true">
                   </xs:element>
                   <xs:element name="UUID" nillable="true">
                   </xs:element>
                   <xs:element name="Status" type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded">
                   </xs:element>
              </xs:sequence>
              <xs:attribute name="Version" type="xs:string" use="required">
              </xs:attribute>
              <xs:attribute name="Name" type="xs:string" use="required">
              </xs:attribute>
         </xs:complexType>
    </xs:schema>
    The sample XML is :
    ___<?xml version="1.0" encoding="UTF-8"?>___
    ___<!--Sample XML file generated by XMLSpy v2010 rel. 2 (http://www.altova.com)-->___
    ___<Service Name="TestService" Version="1.1" xsi:noNamespaceSchemaLocation="Untitled6.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">___
    ___     <DateTime>2001-12-17T09:30:47Z</DateTime>___
    ___     <UUID>text</UUID>___
    ___</Service>___
    wsdlcvt generated the mif file with Service as a FML32 type and all its child elements as "mbstring". We tried to leave as it is and we also tried to replace all the child elements and just had a mif entry for "Service" as a mbstring neither produced a different output...Tried to dump using Ferror32 which did not dump any..._
    The sample C/C++ code as per suggestions were to do the following...
    _1) Have a string with the entire XML for Service_
    xmldata="<Service Name=\"TestService"\ Version="1.1\"_ xsi:noNamespaceSchemaLocation=\"Untitled6.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">_
    _     <DateTime>2001-12-17T09:30:47Z</DateTime>_
    _     <UUID>text</UUID>_
    _</Service>";_
    _2) Use Fmbpack32 to create a mbstring data_
    _memcpy(reqmbptr, (char*)xmldata.data(),xmldata.length());_
    _len=xmldata.length();_
    _Fmbpack32(mbcodeName,reqmbptr,len, packdata,(FLDLEN32 *)&packedlen,0);_
    userlog("Size of packedlen is %d",packedlen);
    3) Add the packed data to the output buffer
    Fadd32(fmlbuffer,Service, packdata,packedlen );
    But we do not see the Service tag populated in the GWWS outbound request.Everything else makes it....any help on how to move ahead would be appreciated...

    It seems you switch to the 10gR3 GA and now the whole XML data is mapped to FLD_MBSTRING.
    I will forward my sample to you by mail, but this sample is not offical sample, it is just QA test case. You can refere it and check what's the difference.
    Please let me know your mail address.
    Regards,
    Xu he

  • XML Schema Collection (SQL Server 2012): Complex Schema Collection with Attribute - Should xs or xsd be used in the coding?

    Hi all,
    I just got a copy of the book "Pro SQL Server 2008 XML" written by Michael Coles (published by Apress) and try to learn the XML Schema Collection in my SQL Server 2012 Management Studio (SSMS2012). I studied Chapter 4 XML Collection of the book
    and executed the following code of Listing 4-8 Complex Schema with Attribute:
    -- Pro SQL Server 2008 XML by Michael Coles (Apress)
    -- Listing04-08.sql Complex XML Schema with Attribute
    -- shcColes04-08.sql saved in C:\\Documents\XML_SQL_Server2008_code_Coles_Apress
    -- 6 April 2015 8:00 PM
    CREATE XML SCHEMA COLLECTION dbo.ComplexTestSchemaCollection_attribute
    AS
    N'<?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="item">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="name" />
    <xs:element name="color" />
    <xs:group ref="id-price" />
    <xs:group ref="size-group" />
    </xs:sequence>
    <xs:attribute name="id" />
    <xs:attribute name="number" />
    </xs:complexType>
    </xs:element>
    <xs:group name="id-price">
    <xs:choice>
    <xs:element name="list-price" />
    <xs:element name="standard-cost" />
    </xs:choice>
    </xs:group>
    <xs:group name="size-group">
    <xs:sequence>
    <xs:element name="size" />
    <xs:element name="unit-of-measure" />
    </xs:sequence>
    </xs:group>
    </xs:schema>';
    GO
    DECLARE @x XML (dbo.ComplexTestSchemaCollection_attribute);
    SET @x = N'<?xml version="1.0"?>
    <item id="749" number="BK-R93R-62">
    <name>Road-150 Red, 62</name>
    <color>Red</color>
    <list-price>3578.27</list-price>
    <size>62</size>
    <unit-of-measure>CM</unit-of-measure>
    </item>';
    SELECT @x;
    GO
    DROP XML SCHEMA COLLECTION dbo.ComplexTestSchemaCollection_attribute;
    It worked nicely. But, I just found out the coding that was downloaded from the website of Apress and I just executed was different from the coding of Listing 4-8 listed in the book: all the <xs: ....> and </xs: ..> in my SSMS2012 are
    listed as <xsd:...> and </xsd:...> respectively in the book!!??  The same thing happens in the Listing 4-3 Simple XML Schema, Listing 4-5 XML Schema and Valid XML Document with Comple Type Definition, Listion 4-6 XML Schema and XML
    Document Document with Complex Type Using <sequence> and <choice>, and Listing 4-7 Complex XML Schema and XML Document with Model Group Definition (I executed last week) too.  I wonder: should xs or xsd be used in the XML
    Schema Collection of SSMS2012?  Please kindly help,  clarify this matter and explain the diffirence of using xs and xsd for me.
    Thanks in advance,
    Scott Chang   

    Hi Scott,
    Using xs or xsd depends on how you declare the namespace prefix.
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="item">
    I've posted a very good link in your last question, just in case you might have missed it, please see the below link.
    Understanding XML Namespaces
    In an XML document we use a namespace prefix to qualify the local names of both elements and attributes . A prefix is really just an abbreviation for the namespace identifier (URI), which is typically quite long. The prefix is first mapped to a namespace
    identifier through a namespace declaration. The syntax for a namespace declaration is:
    xmlns:<prefix>='<namespace identifier>'
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • XML tag with attributes and one value via XSU

    I need to generate a XML structure with attributes in the opening tag, and just one value in the body, like this:
    <PRODUCT-LIST-PRICE NET-PRICE="0" CURRENCY="USD">9.99</PRODUCT-LIST-PRICE>
    Without an object type, I can just create tags like this
    XML3
    <PRODUCT-LIST-PRICE>9.99</PRODUCT-LIST-PRICE>
    (with no attributes, but a single value) via the followig statement
    SELECT sys_xmlgen ('9.99',
    sys.xmlgenformattype.createFormat('PRODUCT-LIST-PRICE')
    ).getClobVal() "XML3"
    FROM DUAL;
    Having an object "productlisteprice_type", defined by
    CREATE OR REPLACE TYPE productlisteprice_type AS OBJECT
    "@NET-PRICE" VARCHAR2(10),
    "@CURRENCY" VARCHAR2(10),
    "PRICE" VARCHAR2(20)
    I just get XML like this
    XML2
    <PRODUCT-LIST-PRICE NET-PRICE="0" CURRENCY="USD">
    <PRICE>9.99</PRICE>
    </PRODUCT-LIST-PRICE>
    (with attributes, but no direct value beneath the "PRODUCT-LIST-PRICE" tag) via the following statement
    SELECT sys_xmlgen ( productlisteprice_type(0,'USD','9.99'),
    sys.xmlgenformattype.createFormat('PRODUCT-LIST-PRICE')
    ).getClobVal() "XML2"
    FROM DUAL;
    Not what I need :-(
    Are there any possibilities in XSU to get the needed XML code? Or do I have to do some post-production via XSQL???
    Another question: Is it possible to use specific keywords like "online" as XML tagnames, via objects? The objects don't allow "online" as a field name...
    Thanks in advance,
    Holger

    I need to generate a XML structure with attributes in the opening tag, and just one value in the body, like this:
    <PRODUCT-LIST-PRICE NET-PRICE="0" CURRENCY="USD">9.99</PRODUCT-LIST-PRICE>
    Without an object type, I can just create tags like this
    XML3
    <PRODUCT-LIST-PRICE>9.99</PRODUCT-LIST-PRICE>
    (with no attributes, but a single value) via the followig statement
    SELECT sys_xmlgen ('9.99',
    sys.xmlgenformattype.createFormat('PRODUCT-LIST-PRICE')
    ).getClobVal() "XML3"
    FROM DUAL;
    Having an object "productlisteprice_type", defined by
    CREATE OR REPLACE TYPE productlisteprice_type AS OBJECT
    "@NET-PRICE" VARCHAR2(10),
    "@CURRENCY" VARCHAR2(10),
    "PRICE" VARCHAR2(20)
    I just get XML like this
    XML2
    <PRODUCT-LIST-PRICE NET-PRICE="0" CURRENCY="USD">
    <PRICE>9.99</PRICE>
    </PRODUCT-LIST-PRICE>
    (with attributes, but no direct value beneath the "PRODUCT-LIST-PRICE" tag) via the following statement
    SELECT sys_xmlgen ( productlisteprice_type(0,'USD','9.99'),
    sys.xmlgenformattype.createFormat('PRODUCT-LIST-PRICE')
    ).getClobVal() "XML2"
    FROM DUAL;
    Not what I need :-(
    Are there any possibilities in XSU to get the needed XML code? Or do I have to do some post-production via XSQL???
    Another question: Is it possible to use specific keywords like "online" as XML tagnames, via objects? The objects don't allow "online" as a field name...
    Thanks in advance,
    Holger

  • Create Checkbox with Attributes from XML file

    Hi
    I have some problem. I want to create some checkbox with attribute from a XML file
    my Xml file look like this:
    <group type="Content Relation" color="255, 255, 255" active="true">
    so I want to create for example a check box with name as Content Relation, Background color is RGB(255, 255, 255) and it's checked. All of these Attribute I have readed and save them as String. My question, how can I create a Color object with the color Attribute from the XML file?
    Is it better if I define my XML file like this:
    <group>
    <type>Content Relation</type>
    <color>
    <red>255</red>
    <green>255</green>
    <blue>255</blue>
    </color>
    <active>true</active>
    </group>

    IMO attributes are much easier to parse then textnodes
    altho
    <color red='255' green='255' blue='255'/>
    might be easier

  • XSLT bug with attributes+in memory DOM

    Hello,
    I know there was a thread about this one some time ago but i
    don't know the current state of this matter, so :
    The XSLT processor has problems with attributes when the DOM was
    build dynamically (attributes are returned as being empty). When
    i save the same DOM, reload it and then do the transform
    attributes are properly transformed.
    The Version 2.0.0.1 of the Java parser states to have solved a
    problem when accessing attributes (bug #920536) but this seems to
    be an other one (i tried 2.0.0.0 and 2.0.0.1 and both had this
    problem).
    Bye Heiko.
    null

    We were unable to reproduce the problem you illustrated. We got
    the output:
    <HTML>
    <BODY>
    the value is : 1
    </BODY>
    </HTML>
    irrespective of whether the lines were commented out. Can you
    describe your environment - JRE/JDK, OS. etc?
    Oracle XML Team
    http://technet.oracle.com
    Oracle Technology Network
    You wrote:
    : Hello,
    : the following program illustrates what i mean :
    : package testing;
    : import oracle.xml.parser.v2.*;
    : import org.w3c.dom.*;
    : import java.io.*;
    : public class XMLTest {
    : public static final void main(String [] args) throws
    : Exception {
    : XMLDocument doc=new XMLDocument();
    : doc.setVersion("1.0");
    : doc.setStandalone("yes");
    : Node root=doc.createElement("ROOT");
    : Node att=doc.createAttribute("value");
    : att.setNodeValue("1");
    : root.getAttributes().setNamedItem(att);
    : doc.appendChild(root);
    : doc.print(new FileOutputStream("c:\\test.xml"));
    : DOMParser parser=new DOMParser();
    : parser.parse(new FileInputStream("c:\\test.xml"));
    : doc=parser.getDocument();
    : XSLStylesheet xsl=new XSLStylesheet(new
    : FileInputStream("c:\\test.xsl"), null);
    : XMLDocument out=new XMLDocument();
    : out.appendChild(new XSLProcessor().processXSL(xsl,
    doc));
    : out.print(System.out);
    : with the stylesheet test.xsl as follows :
    : <?xml version="1.0"?>
    : <xsl:stylesheet
    : xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"
    : xmlns="http://www.w3.org/Profiles/xhtml1-transitional"
    : default-space="strip"
    : indent-result="yes"
    : >
    : <xsl:template match="ROOT">
    : <HTML>
    : <BODY>
    : the value is : <xsl:value-of select="@value"/>
    : </BODY>
    : </HTML>
    : </xsl:template>
    : </xsl:stylesheet>
    : if you run the program as given the result is :
    : the value is:
    : but when you uncomment the lines storing & retrieving the
    : document the result is as i would expect it :
    : the value is: 1
    : Bye Heiko.
    null

  • XML with BSP

    Hello,
    I have created a xml file "data.xml" with a string page
    attribut "xml" and the following page layout.
    <?xml version='1.0' encoding='iso-8859-1'?>
    <%@page language="abap"%>
    <%=xml%>
    in the event handler "On Request" I set the xml variable
    with the following SELECT statement
    SELECT matkl, bez .....
       REPLACE '<' IN bez WITH ' kl '.
       REPLACE '>' IN bez WITH ' gr '.
       CONCATENATE item '<ITEM>' '<VAL>' matkl '</VAL>' '<DES>' bez '</DES>' '</ITEM>' INTO item.
    ENDSELECT.
    CONCATENATE '<GOODSGROUPS>' item '</GOODSGROUPS>' INTO xml.
    As you can see I use the character encoding "iso-8859-1"
    http://www.validome.org/doc/HTML_ge/inter/zeichensaetze.htm
    My problem is that there are some characters that cannot
    be viewed. Why? And which one? (I found out that there
    are problems to view "<" and ">" and I REPLACED this one)
    Error message in Web browser
    <?xml version="1.0" encoding="iso-8859-1" ?>
    - <GOODSGROUPS>
    - <ITEM>
      <VAL />
      <DES />
      </ITEM>
    - <ITEM>
      <VAL>1AA</VAL>
      <DES>Si Scheiben kl150mm</DES>
      </ITEM>
    - <ITEM>
      <VAL>4BF</VAL>
      <DES>geloescht</DES>
      </ITEM>
    The XML page cannot be displayed
    Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
    A semi colon character was expected. Error processing resource 'http://vies12ex.vih.infineon.com:1080/sap/bc/bsp/sap/y_data...
    <ITEM><VAL>5BD</VAL><DES>E undV Pressen</DES></ITEM><ITEM><VAL>5BE</VAL&g...

    bellow u can see the whole abap code in the event handler (OnRequest). the variable "xml" contains the whole xml code, which is dynamically generated.
    DATA: matkl TYPE T023-MATKL,
          wgbez TYPE T023T-WGBEZ,
          item TYPE string,
          bez TYPE string,
          schar.
    item = ''.
    SELECT FMATKL PWGBEZ
      INTO (matkl, wgbez)
      FROM T023 AS F JOIN T023T AS P
        ON FMATKL = PMATKL AND
           FMANDT = PMANDT
    WHERE P~SPRAS = SY-LANGU.
       bez = wgbez.
       REPLACE '<' IN bez WITH ' kl '.
       REPLACE '>' IN bez WITH ' gr '.
       CONCATENATE item '<ITEM>' '<VAL>' matkl '</VAL>' '<DES>' bez '</DES>' '</ITEM>' INTO item.
    ENDSELECT.
    CONCATENATE '<GOODSGROUPS>' item '</GOODSGROUPS>' INTO xml.
    the thing is, everything works without
    the column "wgbez", only in this column are some characters
    which cause troubles. But also in this column there are
    only characters from ISO-8859-1 (Latin-1) character set.
    Thx 4 help!
    BR,
    Rene.

  • Problem parsing XML with schema when extracted from a jar file

    I am having a problem parsing XML with a schema, both of which are extracted from a jar file. I am using using ZipFile to get InputStream objects for the appropriate ZipEntry objects in the jar file. My XML is encrypted so I decrypt it to a temporary file. I am then attempting to parse the temporary file with the schema using DocumentBuilder.parse.
    I get the following exception:
    org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element '<root element name>'
    This was all working OK before I jarred everything (i.e. when I was using standalone files, rather than InputStreams retrieved from a jar).
    I have output the retrieved XML to a file and compared it with my original source and they are identical.
    I am baffled because the nature of the exception suggests that the schema has been read and parsed correctly but the XML file is not parsing against the schema.
    Any suggestions?
    The code is as follows:
      public void open(File input) throws IOException, CSLXMLException {
        InputStream schema = ZipFileHandler.getResourceAsStream("<jar file name>", "<schema resource name>");
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = null;
        try {
          factory.setNamespaceAware(true);
          factory.setValidating(true);
          factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
          factory.setAttribute(JAXP_SCHEMA_SOURCE, schema);
          builder = factory.newDocumentBuilder();
          builder.setErrorHandler(new CSLXMLParseHandler());
        } catch (Exception builderException) {
          throw new CSLXMLException("Error setting up SAX: " + builderException.toString());
        Document document = null;
        try {
          document = builder.parse(input);
        } catch (SAXException parseException) {
          throw new CSLXMLException(parseException.toString());
        }

    I was originally using getSystemResource, which worked fine until I jarred the application. The problem appears to be that resources returned from a jar file cannot be used in the same way as resources returned directly from the file system. You have to use the ZipFile class (or its JarFile subclass) to locate the ZipEntry in the jar file and then use ZipFile.getInputStream(ZipEntry) to convert this to an InputStream. I have seen example code where an InputStream is used for the JAXP_SCHEMA_SOURCE attribute but, for some reason, this did not work with the InputStream returned by ZipFile.getInputStream. Like you, I have also seen examples that use a URL but they appear to be URL's that point to a file not URL's that point to an entry in a jar file.
    Maybe there is another way around this but writing to a file works and I set use File.deleteOnExit() to ensure things are tidied afterwards.

  • Output XML with indentation...

    I've not found an answer to this on the forums so was hoping someone might have discovered what's up since...
    Using the Transformation API with the default JAXP 1.1 transformer (Xalan) and setting the output property "indent" to "yes", the resulting XML contains carriage returns but no indentation as hoped.
    I don't think that indentation is required for the transformer to adhere to the specification but it seems like quite an omission nonetheless.
    Does anyone know how to output indented XML without going to the trouble of adding whitespace text nodes into the document tree?
    Many thanks,
    K.
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.transform(new DOMSource(doc), new StreamResult(out));

    We did it this way:
    import java.util.Map;
    import java.util.HashMap;
    import java.util.Properties;
    import java.io.*;
    import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.XMLReader;
    import org.xml.sax.InputSource;
    import org.apache.xml.serialize.XMLSerializer;
    import org.apache.xml.serialize.OutputFormat;
    import org.apache.xerces.parsers.SAXParser;
    public class XmlPrettyPrinter extends XMLSerializer {
      private Map mapping = new HashMap();
      public XmlPrettyPrinter(StringWriter out, OutputFormat format) {
        super(out, format);
      public static String beautify(String xml) {
        if (xml == null || xml.trim().length() == 0) {
          return "";
        Reader reader = new StringReader(xml);
        XMLReader parser = new SAXParser();
        try {
          parser.setFeature("http://xml.org/sax/features/validation", false);
          OutputFormat format = new OutputFormat();
          format.setIndenting(true);
          format.setIndent(2);
          format.setLineWidth(80);
          StringWriter out = new StringWriter();
          XmlPrettyPrinter serializer = new XmlPrettyPrinter(out, format);
          parser.setContentHandler(serializer.asContentHandler());
          parser.parse(new InputSource(reader));
          return out.toString();
        } catch (Exception e) {
          // do something about this Exception
        return xml;
      public void characters(char[] chars, int offset, int length) throws SAXException {
        String s = new String(chars, offset, length).trim();
        char[] array = s.toCharArray();
        super.characters(array, 0, array.length);
    }Maybe you get an idea what to change in your code.
    Regards,
    hedtfeld

  • Problem while creating xml with cdata section

    Hi,
    I am facing problem while creating xml with cdata section in it. I am using Oracle 10.1.0.4.0 I am writing a stored procedure which accepts a set of input parameters and creates a xml document from them. The code snippet is as follows:
    select xmlelement("DOCUMENTS",
    xmlagg
    (xmlelement
    ("DOCUMENT",
    xmlforest
    (m.document_name_txt as "DOCUMENT_NAME_TXT",
    m.document_type_cd as "DOCUMENT_TYPE_CD",
    '<![cdata[' || m.document_clob_data || ']]>' as "DOCUMENT_CLOB_DATA"
    ) from table(cast(msg_clob_data_arr as DOCUMENT_CLOB_TBL))m;
    msg_clob_data_arr is an input parameter to procedure and DOCUMENT_CLOB_TBL is a pl/sql table of an object containing 3 attributes: first 2 being varchar2 and the 3rd one as CLOB. The xml document this query is generating is as follows:
    <DOCUMENTS>
    <DOCUMENT>
    <DOCUMENT_NAME_TXT>TestName</DOCUMENT_NAME_TXT>
    <DOCUMENT_TYPE_CD>BLOB</DOCUMENT_TYPE_CD>
    <DOCUMENT_CLOB_DATA>
    &lt;![cdata[123456789012345678901234567890123456789012]]&gt;
    </DOCUMENT_CLOB_DATA>
    </DOCUMENT>
    </DOCUMENTS>
    The problem is instead of <![cdata[....]]> xmlforest query is encoding everything to give &lt; for cdata tag. How can I overcome this? Please help.

    SQL> create or replace function XMLCDATA_10103 (elementName varchar2,
      2                                             cdataValue varchar2)
      3  return xmltype deterministic
      4  as
      5  begin
      6     return xmltype('<' || elementName || '><![CDATA[' || cdataValue || ']]>
      7  end;
      8  /
    Function created.
    SQL>  select xmlelement
      2         (
      3            "Row",
      4            xmlcdata_10103('Junk','&<>!%$#&%*&$'),
      5            xmlcdata_10103('Name',ENAME),
      6            xmlelement("EMPID", EMPNO)
      7         ).extract('/*')
      8* from emp
    SQL> /
    <Row>
      <Junk><![CDATA[&<>!%$#&%*&$]]></Junk>
      <Name><![CDATA[SMITH]]></Name>
      <EMPID>7369</EMPID>
    </Row>
    <Row>
      <Junk><![CDATA[&<>!%$#&%*&$]]></Junk>
      <Name><![CDATA[ALLEN]]></Name>
      <EMPID>7499</EMPID>
    </Row>
    <Row>
      <Junk><![CDATA[&<>!%$#&%*&$]]></Junk>
      <Name><![CDATA[WARD]]></Name>
      <EMPID>7521</EMPID>
    </Row>
    <Row>
      <Junk><![CDATA[&<>!%$#&%*&$]]></Junk>
      <Name><![CDATA[JONES]]></Name>
      <EMPID>7566</EMPID>
    </Row>
    <Row>
      <Junk><![CDATA[&<>!%$#&%*&$]]></Junk>
      <Name><![CDATA[MARTIN]]></Name>
      <EMPID>7654</EMPID>
    </Row>
    <Row>
      <Junk><![CDATA[&<>!%$#&%*&$]]></Junk>
      <Name><![CDATA[BLAKE]]></Name>
      <EMPID>7698</EMPID>
    </Row>
    <Row>
      <Junk><![CDATA[&<>!%$#&%*&$]]></Junk>
      <Name><![CDATA[CLARK]]></Name>
      <EMPID>7782</EMPID>
    </Row>
    <Row>
      <Junk><![CDATA[&<>!%$#&%*&$]]></Junk>
      <Name><![CDATA[SCOTT]]></Name>
      <EMPID>7788</EMPID>
    </Row>
    <Row>
      <Junk><![CDATA[&<>!%$#&%*&$]]></Junk>
      <Name><![CDATA[KING]]></Name>
      <EMPID>7839</EMPID>
    </Row>
    <Row>
      <Junk><![CDATA[&<>!%$#&%*&$]]></Junk>
      <Name><![CDATA[TURNER]]></Name>
      <EMPID>7844</EMPID>
    </Row>
    <Row>
      <Junk><![CDATA[&<>!%$#&%*&$]]></Junk>
      <Name><![CDATA[ADAMS]]></Name>
      <EMPID>7876</EMPID>
    </Row>
    <Row>
      <Junk><![CDATA[&<>!%$#&%*&$]]></Junk>
      <Name><![CDATA[JAMES]]></Name>
      <EMPID>7900</EMPID>
    </Row>
    <Row>
      <Junk><![CDATA[&<>!%$#&%*&$]]></Junk>
      <Name><![CDATA[FORD]]></Name>
      <EMPID>7902</EMPID>
    </Row>
    <Row>
      <Junk><![CDATA[&<>!%$#&%*&$]]></Junk>
      <Name><![CDATA[MILLER]]></Name>
      <EMPID>7934</EMPID>
    </Row>
    14 rows selected.
    SQL>

Maybe you are looking for