Does unmarshall operation hold entire XML document in memory?

Hi,
When the unmarshall operation is done on a large XML file, does the root element Java object returned hold the entire XML document in memory? I have a large XML file that I want to unmarshall that contains many <product> elements for example. I want use up as less memory as possible. How would I achieve this?
Thanks.

Yes. I am going with Stax + JAXB to unmarshall. Stax so I could iterate over each element and then use JAXB to unmarshall an element at a time. But the solution is a bit involved. I wanted to do it with just JAXB and so I want to know if JAXB holds the entire content tree in memory if I unmarshall the root element.

Similar Messages

  • How to validate generated XML-Document in Memory by XML-Schema?

    Hi all!
    I have the following problem:
    I am generating a Document using the DOM delivered with Xerces 2.6.2.
    Before I'll send the generated xml-document through network to another system I have to check with my xml-schema if the document is correct.
    In the DOM-FAQ I found an "example" trying to explain how it should work. But with this example the problems begin.
    I am creating my document with this method:
         public void createDocument() {
              myDOM = DOMImplementationImpl.getDOMImplementation();
              doc = myDOM.createDocument("", "documentData", null);
              root = doc.getDocumentElement();
              root.setAttribute(
                   "xmlns:xsi",
                   "http://www.w3.org/2001/XMLSchema-instance");
              //          root.setAttribute("xsi:noNamespaceSchemaLocation", "myScheme.xsd");
              domConfig = ((DocumentImpl) doc).getDomConfig();
              domConfig.setParameter(
                   "schema-location",
                   "file:///d:/workspace/XMLProject/WebContent/WEB-INF/myScheme.xsd");
              domConfig.setParameter("error-handler", new EHandler());
              domConfig.setParameter("validate", Boolean.TRUE);
         }In the line getting the domConfig, it is getting differeing to the example: The example is like this:
    import org.w3c.dom.Document;
    import org.w3c.dom.DOMConfiguration;
    import org.w3c.dom.ls.LSParser;
    Document document = builder.parseURI("data/personal-schema.xml");
    DOMConfiguration config = document.getConfig();
    config.setParameter("error-handler",new MyErrorHandler());
    config.setParameter("validate", Boolean.TRUE);
    document.normalizeDocument();They get the DOM-Configuration from the document-Object, but my document-Object has no "getConfig()" and only after type-casting I get a getDomConfig()-Method to get the configuration.
    Then I fill my document and call                
    ((DocumentImpl) doc).normalizeDocument();When I run my Application I get the following error:
    org.w3c.dom.DOMException: FEATURE_NOT_SUPPORTED: The parameter schema-location is recognized but the requested value cannot be set.
         at org.apache.xerces.dom.DOMConfigurationImpl.setParameter(Unknown Source)
         at xmlProject.createDocument(Convert.java:63)
         at xmlProject.Convert.main(Convert.java:154)I tried several ways to get the validation without success.
    The next question is how I should refer to my xml-schema (which path) and where to place it relative to my jar I will generate, because I will have no webserver I could place it on.
    Has anyone any experience with validating a document created and not placed on disc?
    I have also another question to SAX: I read, that it is reading a document without saving it in the memory. I think this means that if I am validating it by SAX it will be read once and for parsing it will be read a second time. If I would transfer the document over an tcp-connection, I only have the document once in my inputstream and after validation it would be consumed I think. But what can I parse then? Or did I missed a detail with the function of the SAX?
    Thank you for your help!
    Yours
    Christian

    static final String schemaSource = argv[0];
    static final String JAXP_SCHEMA_SOURCE =
    "http://java.sun.com/xml/jaxp/properties/schemaSource";
    DocumentBuilderFactory factory =
    DocumentBuilderFactory.newInstance();
    factory.setAttribute(JAXP_SCHEMA_SOURCE,
    new File(schemaSource));

  • How to save sections of a single XML Document to multiple tables ?

    Firstly, I apologise for the long e-mail but I feel it's necessary in order to clarify my problem/question.
    The XML document representation below stores information about a particular database. From the information in the XML document you can tell that there is a single database called "tst" which contains a single table called "tst_table". This table in turn has two columns called "CompanyName" & "Country".
    I want to use Oracle's XML SQL Utility to store this information into three seperate database tables. Specifically, I want to store the information pertaining to the database (i.e. name etc.) in one table, the information pertaining to the table (name, no. of columns etc.) in another and the information pertaining to the columns (name, type etc.) in yet another table.
    I have seen samples where an entire XML Document is saved to a database table but I cannot find any examples where different sections of a single XML Document are saved into different database tables using the XML SQL Utility.
    Can you please tell me the best approach to take in order to accomplish this . Does it involve creating an XMLDocument and then extracting the relevant sections as XMLDocumentFragment's, retrieving the String representations of these XMLDocumentFragment's and passing these strings to the OracleXMLSave.insertXml() method.
    Is this the best approach to take or are there any other, perhaps more efficient or elegant, ways of doing this ?
    Thanks in advance for your help
    - Garry
    <DATABASE id="1" name="tst">
    <TABLES>
    <TABLE name="tst_table">
    <NAME>Customers</NAME>
    <COLUMNS>
    <COLUMN num="1"> <COLID>2</COLID>
    <COLNAME>CompanyName</COLNAME>
    <COLTYPE>Text</COLTYPE>
    </COLUMN>
    <COLUMN num="2">
    <COLID>3</COLID>
    <COLNAME>Country</COLNAME>
    <COLTYPE>Text</COLTYPE>
    </COLUMN>
    </COLUMNS>
    </TABLE>
    </TABLES>
    </DATABASE>
    null

    See this thread;
    {thread:id=2180799}
    Jeff

  • Best class to use to cache an XML document

    Hello all,
    I have an utility class representing an XML document, used withing a web application. This document shall be cached in the session since within a request and during the sessions I read it often and to several other things like XPath and XSLT.
    But I am having problems due to this Bug:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6322678
    and keep bad file descriptor errors due to these stream "specialities". There is a standard way of using cached+precompiled XSL templates and I wonder if there is a similar things for XML documents.
    So I need an internal variable in my class containing the raw XML document - so using streams is not an ideal solution in regards of the bug - i am getting "bad file descriptor" errors from time to time.
    I am playing with the idea of storing the XML document within a simple String and create the required Class from it for the according operations like XPath evaluation and XSL transformation. But I think that is quite more resource hungry than reading the XML document from the filesystem each time...
    Has anyone some hints on how to keep an XML document in memory internally?
    Thanks and regards,
    Timo

    Rehi,
    So, everything works really fine! Thanks. As promised, here some examples
    with bad indentations etc...:
    Doing XSL transformation:
    import java.io.StringWriter;
    import org.w3c.dom.Document;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.Templates;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.stream.StreamResult;
    TransformerFactory tFac = TransformerFactory.newInstance();
    Templates compiledXslt = tFac.newTemplates(sheet);
    Transformer transformer = compiledXslt.newTransformer();
    StringWriter sw = new StringWriter();
    StreamResult sr = new StreamResult(sw);
    transformer.transform(new DOMSource(this.doc), sr);
    System.err.println(sw.toString());************************
    Doing XPath was a surprise and was originally my problem (I called evaluate() with an InputStream that occassioannly failed), I tried also here with new DOMSource() what also failed although not being null or so... funny: evaluate() can directly be called w/ dom.Document:
    import javax.xml.xpath.XPath;
    import javax.xml.xpath.XPathFactory;
    import org.w3c.dom.Document;
    (this.doc is a org.w3c.dom.Document)
    public String getXPathEvaluationAsString(String expr) {
         try {
              XPath xp = XPathFactory.newInstance().newXPath();
              return (String)xp.evaluate(
                   expr,
                   this.doc,
                   XPathConstants.STRING
         } catch(Exception e) {
              e.printStackTrace();
         return " ";
    }Thanks and regards,
    Timo

  • Replacing special characters from xml document/text inside element

    Hi
    Is there any way to replace the xml codes to special characters inside an entire xml document/ for a text in element.
    I want to get the xml codes to get replaced to respective special character(for any special character)
    Please see the sample xml xml element below
    <Details>Advance is applicable only for &lt; 1000. This is mentioned in Seller&apos;s document</Details>
    Thanks in advance .. any help will be highly appreciated.

    So, just to be sure I understand correctly, you want this :
    <Details>Advance is applicable only for &lt; 1000. This is mentioned in Seller&apos;s document</Details>
    to be converted to :
    <Details>Advance is applicable only for < 1000. This is mentioned in Seller's document</Details>
    If so, I'll say again : the resulting XML document will be invalid.
    Extensible Markup Language (XML) 1.0 (Fifth Edition)
    The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they MUST be escaped using either numeric character references or the strings " &amp; " and " &lt; " respectively. The right angle bracket (>) may be represented using the string " &gt; ", and MUST, for compatibility, be escaped using either " &gt; " or a character reference when it appears in the string " ]]> " in content, when that string is not marking the end of a CDATA section.
    Ask whoever "they" are why they would want to work with not wellformed XML.

  • XML document in HTTP response

    Hello,
    I try to write a portal component, that provides an XML document. The component must be reachable via a URL. It generates an XML document from portal content. The generated XML document must be available using the URL.
    I tried to solve this by implementing an AbstractPortalComponent iView. Inside the doContent method I write the XML document into the IPortalComponentResponse. The problem is, that the response does not only include the XML document, but the XML data is included inside an HTML document. I already set the EPCFLevel in component-profile to 0. So there is very few JavaScript left inside the HTML document. But I don't want any HTML at all. I want only the pure XML document inside the HTTP response.
    Does anybody know a way to make a plain XML document available at an URL?
    Thanks, best regards, Oliver

    Try something like this in the docontent method
    HttpServletResponse resp = request.getServletResponse(true);
    resp.setContentType("text/xml");
    resp.getOutputStream().write(bytes);

  • String representation of the xml document

    hi, I have created the following xml document using the DOM api. I want to the "function" to return a "string" - which represents the xml document i created. How do u do that?
    As of now it doesnt return anything...
    How do u return the entire xml document as character data..? just like
    <root><elements>data</elements></root>....
    anyhelp would be great.
    import java.io.*;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import org.w3c.dom.*;
    public class test1{
    private static void function()throws IOException, DOMException{
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance ();
    DocumentBuilder db = dbf.newDocumentBuilder ();
    Document doc = db.newDocument ();
    Element record = doc.createElement ("record");
    Element name = doc.createElement ("name");
    Element address = doc.createElement ("address");
    Element zip = doc.createElement ("zip");
    Text nameText = doc.createTextNode("bill");
    Text addressText = doc.createTextNode("128, washington");
    Text zipText = doc.createTextNode("10000");
    doc.appendChild(record);
    record.appendChild(name);
    name.appendChild(nameText);
    record.appendChild(address);
    address.appendChild(addressText);
    record.appendChild(zip);
    zip.appendChild(zipText);
    public static void main (String argv [])throws Exception {
    function();
    }

    Brent,
    Looks like you're using the Sun Java Parser. I'll show you how to do it with the Oracle XML Parser and you can extrapolate...
    Document doc = new XMLDocument();
    // Stuff here to build up the DOM Doc
    // with elements, etc.
    // Print the Document to a String
    StringWriter sw = new StringWriter();
    // Wrap the stringwriter in a printwriter
    PrintWriter pw = new PrintWriter(sw);
    // Print to the printwriter
    ((XMLDocument)doc).print(pw);
    // return the string from the stringwriter
    return sw.toString();

  • Can I append an XML Document into another?

    I have a large xml document which I open into coldfusion (mx
    7), and then a smaller group of files that are opened into thier
    own xml objects. After some customization of xml text values, I
    want to append the smaller xml documents into the larger document
    at specific positions within the document tree.
    I have the code that I thought would do this, using an
    arrayappend function, but what happens is that only the root
    element of the smaller (inserted) xml document is placed into the
    main document.
    Is this possible, or do I need to modify the code so that the
    entire tree of xml data that I am appending is created on the
    fly?

    Personally I do this with XSLT.
    <cfxml variable="doc1">
    <root>
    <member id="10">
    <name>Ian</name>
    <sex>male</sex>
    </member>
    </root>
    </cfxml>
    <cfxml variable="doc2">
    <root>
    <member id="1">
    <name>Joe</name>
    <sex>male</sex>
    </member>
    <member id="2">
    <name>John</name>
    <sex>male</sex>
    </member>
    <member id="3">
    <name>Sue</name>
    <sex>female</sex>
    </member>
    </root>
    </cfxml>
    <cffile action="write" file="#expandPath("/")#\doc2.xml"
    output="#ToString(doc2)#" nameconflict="overwrite">
    <!--- METHOD ONE using a depreciated and undocumented
    method --->
    <cfset newNode = doc1.root.member.cloneNode(true)>
    <cfset doc2.changeNodeOwner(newNode)>
    <cfset doc2.root.appendChild(newNode)>
    <cfdump var="#doc2#" label="Merged by hidden functions"
    expand="no">
    <!--- METHOD TWO using XSLT --->
    <!--- create an xsl docutment--->
    <cfoutput>
    <cfsavecontent variable="transformer">
    <xsl:stylesheet xmlns:xsl="
    http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:output method="xml"/>
    <!--load the merge file -->
    <xsl:variable name="emps"
    select="document('#expandPath("/")#\doc2.xml')"/>
    <!--- this line references and XML file to be combined
    with the main file,
    I wonder if there is a way to use an XML document in memory
    here? --->
    <!-- combine the files -->
    <xsl:template match="/">
    <root>
    <!-- select all the child nodes of the root tag in the
    main file -->
    <xsl:for-each select="root/child::*">
    <!-- copy the member tag -->
    <xsl:copy-of select="."/>
    </xsl:for-each>
    <!-- and all the child nodes of the root tag in the merge
    file -->
    <xsl:for-each select="$emps/root/child::*">
    <!-- copy the member tag -->
    <xsl:copy-of select="."/>
    </xsl:for-each>
    </root>
    </xsl:template>
    </xsl:stylesheet>
    </cfsavecontent>
    </cfoutput>
    <!--- create a combined xml document --->
    <cfset doc2 = XMLparse(XMLtransform(doc1,transformer))>
    <cfdump var="#doc2#" label="Merged by XSLT"
    expand="no">

  • Assigning XML Document Message to XSD Instance

    Hi,
        I have constrcuted below  XML Document mesaage  ( System.XML.XMLDocument) and I have created xsd schema for the same and I would like to assign the XML Document to the xsd schema instace inside Orchestration.
    Pl let me know what is How to assign inside Orchestration.
    <BacklogMaterial SAPMaterialNumber="100010" xmlns="http://www.myorg.com/InventoryBroker">
    <Quantity UOM="EA">41</Quantity>
    </BacklogMaterial>

    i think since you already have a variable of type System.XML.XMLDocument
    you can directly assign that to the xsd schema message variable
    like say you have following variables
    1. xmldoc that holds the XML
    Document mesaage
    2. outputmsg  variable of type xsd schema instance
    then you can directly assign as
    outputmsg=xmldoc
    make sure you use message assignment shape.
    Please mark the post as answer if this answers your question. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

  • Updating XML document using DOM only updates in memory

    I am trying to update an element value but it only gets updated in the memory and displayed. It does not physically change the xml document when I look after running the program.
    Here is the code I am trying to run :
    Please let me know what I am doing wrong.
    static private Document findReplace(Document document, String elementName,
    String valueToFind, String valueToReplace)
    int i;
    int k;
    NodeList children;
    Element docRoot= document.getDocumentElement(); // get root
    NodeList elements = docRoot.getElementsByTagName(elementName);
    if (elements !=null)
         for (i=0;i<elements.getLength(); i++)
         if (elements.item(i).hasChildNodes())
         children = elements.item(i).getChildNodes();
    for(k=0;k<children.getLength(); k++)
              if (children.item(k).getNodeType() ==
                   org.w3c.dom.Node.TEXT_NODE){
              if(children.item(k).getNodeValue().equals(valueToFind))
         children.item(k).setNodeValue(valueToReplace);
    Thanks !

    Document document;
                   TransformerFactory tFactory =
                    TransformerFactory.newInstance();
                   Transformer transformer = tFactory.newTransformer();
                   DOMSource source = new DOMSource(document);
                   StreamResult result = new StreamResult(new File
                   (c:/output/outputXml.xml));
                   transformer.transform(source, result);

  • Mapping XML documents in Oracle

    I am a newbie in Oracle.
    I would like to know how to store entire XML documents in CLOBS.
    Since yesterday I hear about XSQL, and I was wondering if nobody had some sample code to realize this mapping.
    Thanks in advance for your help
    Mamoudou

    OTN has some sample apps that might interest you:
    [list][*]Customizing Web Content
    [*]B2B with XML
    [*]WebStore B2B Exchange
    [*]XML Flight Finder
    [list]
    Regards,
    -rh

  • How can we forward XML document from Routing Engine to Mapviwer!!!

    Does anyone try to forward XML document from routing engine to Mapviwer. Like spatial coordinate system from Routing engine. Could you help me how to accomplish this problem. Thank much much....

    Just open an HTTP connection to MapViewer's server url (ususally http://host:port/mapviewer/omserver) and send an XML map request to it using POST. You can do that from any language that supports such a connection.
    Inside the xml map request you can attach the routing result (a series of coordinates i imagine) as dynamic geo-features. You can also specify any base map/layer information in the xml map req provided you have defined such map/themes. DTD of mapviewer's map req is in the Users Guide, which is on OTN site mapviewer http://otn.oracle.com/products/mapviewer.

  • Loading XML document for DOM parsing

    Can anyone suggest other API's to load a XML document into memory so they can be parsed using the DOM with Java?(e.g. The "load(url)" interface method specific to IE5)
    Thanks

    Check out the DOMSample.java code came with the XML Parser for Java v2 download.
    Oracle XML Team

  • XML document does not appear to contain a properly formed DOCTYPE header

    Hi,
    I've created an ejb which uses the studio API to start/execute etc the workflow
    tasks in a generic way. The same ejb contain certain method which I want to use
    as business operations in my workflows. However, when I deploy this ejb as a separate
    application by putting the required jar files in class path it works fine, but
    when I deploy it as a part of WLI application for accessing the business operations
    in workflow I'm getting the following error. I'm entering ejbcomponent entry under
    the wli application tag of config.xml and putting the jar file in the lib directory
    where other jar files are placed. I couldn't understand the reason why it is failing
    when I deploy it as a part of WLI application and not when I deploy it independently.
    Module Name: TestWLPI, Error: The XML parser encountered an error in your deployment
    descriptor. Please ensure that your DOCTYPE is correct. You may wish to compa
    re your deployment descriptors with the WebLogic Server examples to ensure the
    format is correct. The error was:
    weblogic.xml.process.ProcessorFactoryException: XML document does not appear to
    contain a properly formed DOCTYPE header
    at weblogic.xml.process.ProcessorFactory.getProcessor(ProcessorFactory.java:281)
    at weblogic.xml.process.ProcessorFactory.getProcessor(ProcessorFactory.java:224)
    at weblogic.ejb20.dd.xml.DDUtils.processXML(DDUtils.java:267)
    at weblogic.ejb20.dd.xml.DDUtils.processXML(DDUtils.java:242)
    at weblogic.ejb20.dd.xml.DDUtils.processAltDD(DDUtils.java:220)
    at weblogic.ejb20.dd.xml.DDUtils.createDescriptorFromJarFile(DDUtils.java:102)
    at weblogic.ejb20.deployer.EJBModule.loadEJBDescriptor(EJBModule.java:500)
    at weblogic.ejb20.deployer.EJBModule.loadDescriptor(EJBModule.java:207)
    at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:714)
    at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:555)
    at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:458)
    at weblogic.management.deploy.slave.SlaveDeployer.prepareAllStagedApplications(SlaveDeployer.java:490)
    at weblogic.management.deploy.slave.SlaveDeployer.initialize(SlaveDeployer.java:253)
    at weblogic.management.deploy.DeploymentManagerServerLifeCycleImpl.initialize(DeploymentManagerServerLifeCycleImpl.java:150)
    at weblogic.t3.srvr.ServerLifeCycleList.initialize(ServerLifeCycleList.java:54)
    at weblogic.t3.srvr.T3Srvr.initialize1(T3Srvr.java:782)
    at weblogic.t3.srvr.T3Srvr.initialize(T3Srvr.java:594)
    at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:282)
    at weblogic.Server.main(Server.java:32)

    javax.xml.stream.XMLStreamException: javax.xml.stream.XMLStreamException: Premature end of file encountered
    at weblogic.xml.stax.XMLStreamReaderBase.prime(XMLStreamReaderBase.java:80)
    at weblogic.xml.stax.XMLStreamReaderBase.setInput(XMLStreamReaderBase.java:99)
    at weblogic.xml.stax.XMLStreamInputFactory.createXMLStreamReader(XMLStreamInputFactory.java:316)
    at weblogic.xml.stax.XMLStreamInputFactory.createXMLStreamReader(XMLStreamInputFactory.java:49)
    at weblogic.application.descriptor.BasicMunger2.<init>(BasicMunger2.java:110)
    at weblogic.application.descriptor.BasicMunger2.<init>(BasicMunger2.java:128)
    at weblogic.application.descriptor.VersionMunger.<init>(VersionMunger.java:74)
    at weblogic.application.descriptor.VersionMunger.<init>(VersionMunger.java:63)
    at weblogic.servlet.internal.WlsWebAppReader2.<init>(WlsWebAppReader2.java:59)
    at weblogic.servlet.internal.WebAppDescriptor$MyWlsWebAppDescriptor.createXMLStreamReader(WebAppDescriptor.java:316)
    at weblogic.application.descriptor.AbstractDescriptorLoader2.createDescriptorBean(AbstractDescriptorLoader2.java:402)
    at weblogic.application.descriptor.AbstractDescriptorLoader2.loadDescriptorBeanWithoutPlan(AbstractDescriptorLoader2.java:759)
    Any Suggestions plz???
    Thanks

  • XML Document Format for JDBC Receiver(Between operation)

    Hello everybody,
    is there a way to use a BETWEEN operation for the key in a SELECT XML document format????????, I need to filter in the Where for different Statements in teh strcuture as BETWEEN, thanks in advance.
    Regards,
    Julio

    http://help.sap.com/saphelp_nw70/helpdata/en/2e/96fd3f2d14e869e10000000a155106/content.htm
    Not sure but Check the option of
    <key1>
         <col2 compareOperation=u201DLTu201D>val2old</col2>
         <col2 compareOperation=u201DGTu201D>val2old</col2>
    </key1>
    Thanks,
    Beena.

Maybe you are looking for

  • Issues with basic VPN setup and split tunneling

    I have created an SSL VPN to a CISCO ASA 8.6 running ASDM 6.6. Im able to connect to the VPN and reach all the devices with the LAN but  Im not able to browse the web. When I enable the split tunnel Im able  to browse the web but then Im not able to

  • Error message when installing Indesign CS3 trial. I need help ASAP

    I have searched the forums and adobe.com and have tried everything that I saw. None of it worked for me. I have tried and tried to install Indesign CS3 trial. I keep getting the error message: Indesign has encountered a problem and must close. I have

  • How to include mxml in a panel

    hi, I have a set of mx:Panels The content to be displayed inside each panel is structured in an mxml file. How do i reference or place this mxml file inside the panels. Thanks, Lucky

  • Migration from 8.1.7/ windows2000  to 10g/linux

    what is the step by step procedure to take export from 8.1.7 / windows 2000 and import into 10g / centos( linux). option 1: First upgrade from 8.1.7 / windows 2000 server to 10g / windows 2000 server and then 10g / windows 2000 server to 10g/ linux.

  • Altering copied SAP report layout

    I've copied SAP std report from investment management (in IME2) to create my own layout. I've copied the report and form, and have alterred the form to my liking. When I execute the report, the summary section at the bottom of the report appears corr