XML output with multiple tags in one line

I have not done much XML exporting with SQL. Previously I had just been ending my SQL queries with
FOR XML RAW ('Company'), ROOT ('Companies'), ELEMENTS;
and it formatted my query nicely in an XML output. That put every column name as a tag and the cell data within the tag.
However, now the criteria has changed on me. I need to create a tag with multiple sub tags in it.
Example: <Location Floor="10" Suite="512" DoorType="Metal">
But I'll still need other tags to be normal in the XML output such as
<Address>123 Fake St</Address>
<City>Springfield</City>
<Location Floor="10" Suite="512" DoorType="Metal">
Is there any way to get this XML mixed in the output like above?
Thank you for any help. 

Hi, you can FOR XML PATH for a finer degree of control over your XML.  Use the @ symbol to create attributes.  Here's a simple example:
DECLARE @t TABLE ( rowId INT IDENTITY PRIMARY KEY, [address] VARCHAR(50), city VARCHAR(30), floor INT, suite INT, doorType VARCHAR(20) )
INSERT INTO @t VALUES
( '123 Fake St', 'Springfield', 10, 512, 'Metal' )
SELECT
[address] AS "Address",
city AS City,
[floor] AS "Location/@Floor",
suite AS "Location/@Suite",
doorType AS "Location/@DoorType"
FROM @t
FOR XML PATH ('Company'), ROOT ('Companies'), ELEMENTS;

Similar Messages

  • XML Output with multiple categories

    I am driving myself insane trying to get this to output and I can't seem to find much on the internet that is helpful. Sometimes there is 1 category and sometimes there could be 2.
    For example:
    <Article>
    <Heading>Study: Ban on cell phone use hasn't reduced accident rate</Heading>
    <Date>01/02/2010</Date>
    <Contents>Content regarding cell phone use.</Contents>
    <Categories>
    <Category ID="438024898">General Auto News</Category>
    <Category ID="438022448">Electronics</Category>
    </Categories>
    </Article>
    I set myitems with the xml search and can manage to output everything below perfectly, except for the multiple categories.
    <cfloop from="1" to="#arrayLen(myItems)#" index="i">
    #myItems[i].Heading.xmltext#
    #myItems[i].Categories.Category.xmltext#        this outputs only the first one, but I can not seem to get the second.
    </cfloop>
    Thanks for any help in advance!!!!

    <cfloop from="1" to="#arrayLen(myItems[i].Categories.Category#" index="c"
        #myItems[i].Categories.Category[c].xmltext#
    </cfloop>
    OR
    #myItems[i].Categories.Category[1].xmltext#
    #myItems[i].Categories.Category[2].xmltext#
    Category is just a nested array just like your myItems was.
    Or you could do another xmlSearch if you prefer.

  • One Output with multiple communication types

    Hello,
    My requirement is to print the document as well as send an email to the customers from the same output.  Basically One output with multiple communication types ( PRINT  & EMAIL).  How to configure this in the output type configuration area? Please reply. Thanks

    This should be possible with the same output type,
    have the output type defined with multiple medium in NACE under processing routines. (say print out in one line & external send in another).
    have the condition record maintained appropriately for different customers with different medium.
    Note: if your access has customer, dont think you can maintain both 1 & 5 for the same access.
    if this functionality is required, i think you can acheive this by maintaining the output under different access, but this will not ensure the same condition type flowing into the document unless the earlier condition type goes to processed status.
    Thanks & Regards
    Ilango

  • Having a xml output with custom xml tags

    Hi All,
    I have a requirement where we need to generate an xml output with a custom set of tags as given below.
    <templates>
    <list>
    <List_no></list_no>
    <List_name> </List_name>
    </List>
    </templates>
    I am not sure how to get the list part as tags within tags.
    I am able to get the output if the tag level is just one level like ,
    <templates>
    <List_no></list_no>
    <List_name> </List_name>
    </List>
    </templates>
    Does anybody know how I could get the multi-level tags. Any help would be much appreciated. Thank you all.
    -Vin

    Hi, you can FOR XML PATH for a finer degree of control over your XML.  Use the @ symbol to create attributes.  Here's a simple example:
    DECLARE @t TABLE ( rowId INT IDENTITY PRIMARY KEY, [address] VARCHAR(50), city VARCHAR(30), floor INT, suite INT, doorType VARCHAR(20) )
    INSERT INTO @t VALUES
    ( '123 Fake St', 'Springfield', 10, 512, 'Metal' )
    SELECT
    [address] AS "Address",
    city AS City,
    [floor] AS "Location/@Floor",
    suite AS "Location/@Suite",
    doorType AS "Location/@DoorType"
    FROM @t
    FOR XML PATH ('Company'), ROOT ('Companies'), ELEMENTS;

  • Can we have a multiple TAGS in single line.Pls let me know

    Hi Team,
    Can we have a multiple TAGS in single line.Ie 2 open tags and 2 close tags in XML..Pls let me know

    chk this xml file
    <ns0:Test1>  
    <Address><street>LinkinPark</street><city>Paris</city></Address>
    </ns0:Test1>
    But I am not sure whether u can have any value for parent node in 7.0 for like node Address... only child nodes can have value..
    It can be done in 7.1
    Regards,
    Syed

  • Loading xml file with multiple rows

    I am loading data from xml files using xsl for transformation. I have created xsl's and loaded some of the data. In an xml file with multiple row, it's only loading one (the first) row. Any idea how I can get it to read and load all the records in the file???

    Could some please help me with the above. I desparately need to move forward.

  • Am I able to tag a data point of a spreadsheet that is being created by a datalogging VI such that at the end I have the data with multiple tags which corelate to events during a measurement cycle

    Am I able to tag a data point of a spreadsheet that is being created by a datalogging VI such that at the end I have the data with multiple tags which corelate to events during a measurement cycle
    My final need is to take data from a datalogging VI and store it in a spreadsheet with tags that corespond to events in a subVI which is controlling motor movement. This will allow users to view all data and mark the relevent data for analysis. As usual, user want everthing but with conditions.

    Sure. What you do is take the numeric value acquired, the tags you want, and build them into an array. So now, when you write to the spreadsheet, you'll have a 2D array. One thing you have to keep in mind is that all elements of an array have to be of the same type. So if your tags are strings, you'll have to convert your numeric data into strings as well.

  • How can I activate multiple tags at one time?

    How can I activate multiple tags at one time?

    I'm pretty sure you can run this on a sub tree of /etc/tags
    http://dev.day.com/docs/en/cq/current/wcm/page_publish/tree_activate.html

  • HP Officejet 6500A How do I scan a document with multiple pages into one file?

    HP Officejet 6500A Plus e-All-in-One Printer - E710n
    Windows 7 (64 bit)
    How do I scan a document with multiple pages into one file?  My old printer (psc 2110) asked after each scan if I wanted to scan another page.  At the end I had one pdf file with multiple pages.
    This new one creates one file for each page and I cannot find a way to create one pdf file with multiple pages.
    This question was solved.
    View Solution.

    Hi mpw101,
    If you load the papers into the ADF - Automatic Document Feeder, and then select Document to PDF then they will all be scanning into one file. Let me know if this works for you?
    I am an HP employee.
    Say Thanks by clicking the Kudos Star in the post that helped you.
    Please mark the post that solves your problem as "Accepted Solution"

  • Adding an XML doc with repeating tags

    Hello,
    Can anyone tell me how I take an XML document with a tag that can appear from 0-N times and map it to a database table? I am currently using a supertable and then using triggers to move data to the appropriate spot but am stuck on how to map tags that don't correspond 1-1.
    My structure is like
    <product>
    <name>
    <model>
    <cost>
    <feature>* (0-N)
    <spec>* (0-N)
    </product>
    Thanks.
    null

    Do a getElementsByTagName on a node and do a
    insert on each node found.

  • Problems with multiple idocs in one file ( Inbound file )

    HI,
    Thanks in Advance for your suggestions.. Highly appreciated.
    We have problems with multiple IDocs in one file.
    We are using XIB ( Amtrix ) as Middleware to receive the files.
    Curretenly When the file contains one IDoc then there is no problem. IDoc is created and everything is ok.
    If file contains two IDocs ( for example two messages ORDERS and DELVERY ) then it is creating two IDocs but both IDocs contains ORDERS plus DELIVERY segements information. That is the problem. Some how SAP unable to differentiate the IDocs in the file.. But it knows that how many idocs are there in the file..because it is creating exact number of idocs.
    We are using TRFC port ... Do I need to change it to File port..
    When we have more than one idoc do we need set any parameter in the file ...

    Thanks for the swift response. Always ideas are useful.
    As of now , Middleware cannot split the file.
    Thing is SAP is creating two Idocs with different message types. Problem is First IDoc contains ORDERS message type but also DELIVERY segments as well. Second IDoc with DELIVERY message tyoe but ORDERS segments as well... This is the problem... I think we are missing some field activation in file for EDIDC record.
    As far as I know file port supports the number of IDocs in one file.. Hope TRFC port also supports that

  • How to extract a clob xml string with multiple row of table tag. in 10g

    i have a xml value like:
    <table><c1>0</c1><c2>Mr</c2><c3>abc</c3><c4>Sharma</c4></table>
    <table><c1>0</c1><c2>Mrs</c2><c3>abcd</c3><c4>Sharma</c4></table>
    <table><c1>0</c1><c2>Mr</c2><c3>sabc</c3><c4>Sharma</c4></table>
    <table><c1>0</c1><c2>Mrs</c2><c3>sdabc</c3><c4>Sharma</c4></table>
    <table><c1>0</c1><c2>Mr</c2><c3>dabc</c3><c4>Sharma</c4></table>
    <table><c1>0</c1><c2>Mr</c2><c3>adbc</c3><c4>Sharma</c4></table>
    i want to insert each of <c> value in a table with respective columns according c1,c2,c3,c4
    pls suggest me what to do
    I use extract(xml, '/table) tab but it just read first one line & return error for other

    Can you plz explain to me thisIt is because you did not provide us with a valid xml structure so I used 11g's xmlparse function to create a xmltype even with the xml not being valid (no root tag).
    With a valid xml structure I could use the xmltype constructor instead and go on the same way as before:
    SQL> select *
      from xmltable (
             'table'
             passing xmltype ('
                            <root>
                            <table><c1>0</c1><c2>Mr</c2><c3>abc</c3><c4>Sharma</c4></table>
                            <table><c1>0</c1><c2>Mrs</c2><c3>abcd</c3><c4>Sharma</c4></table>
                            <table><c1>0</c1><c2>Mr</c2><c3>sabc</c3><c4>Sharma</c4></table>
                            <table><c1>0</c1><c2>Mrs</c2><c3>sdabc</c3><c4>Sharma</c4></table>
                            <table><c1>0</c1><c2>Mr</c2><c3>dabc</c3><c4>Sharma</c4></table>
                            <table><c1>0</c1><c2>Mr</c2><c3>adbc</c3><c4>Sharma</c4></table>
                            </root>').extract ('root/table')
             columns c1 number path 'c1', c2 varchar2 (4) path 'c2', c3 varchar2 (6) path 'c3', c4 varchar2 (6) path 'c4')
            C1 C2     C3        C4      
             0 Mr     abc       Sharma  
             0 Mrs    abcd      Sharma  
             0 Mr     sabc      Sharma  
             0 Mrs    sdabc     Sharma  
             0 Mr     dabc      Sharma  
             0 Mr     adbc      Sharma  
    6 rows selected.

  • Please Help Xml output with extra lines after removeNodeChild

    Hi guys. I'm having trouble googling this out.
    Here is the problem. Given an xml document. I read it on my app and manipulate it, then save it when I am done.
    When I remove a child, the output files shows all the extra lines from the formatting and indent. So it looks like a big hole in the xml file after the node is removed. Here is an example
    <bookshelf>
    <books>
    <book>
    <isbn>3349583080580584308</isbn>
    <author>Jon Stewart</author>
    </book>
    <book>
    <isbn>9900909770543356488</isbn>
    <author>Stephen Colbert</author>
    </book>
    </books>
    </bookshelf>
    Node parentNode = jonStewartNode.getParentNode();
    parentNode.removeChild (jonStewartNode);The result of this is the following xml.
    <bookshelf>
    <books>
    <book>
    <isbn>9900909770543356488< /isbn>
    <author>Stephen Colbert</author>
    </book>
    </books>
    </bookshelf>
    How can I output the xml without this extra lines?
    Thanks in advance,
    f(t)
    PS: here is the initialization, and configuration of the TransformerFactory, and Transformer, and finally the save method.
         * Initializes factory instances and member variables.
        private void initialize(){
            try{
                //obtain a trasformer factory to save the file
                this.transformerFactory = TransformerFactory.newInstance();
                this.transformerFactory.setAttribute("indent-number", 4);
                //obtain the transforme
                this.transformer = this.transformerFactory.newTransformer();
                //setup transformer
                this.transformer.setOutputProperty(OutputKeys.METHOD, "xml");
                this.transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                //this.transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount ", "4");
            }catch(TransformerConfigurationException tcex){
                this.logger.logException(this, "errors.storage.xml.configuringXmlTransformer", true, tcex);
         * Saves the DOM document to the XML file.
        private void saveDocument(){
            //verify that the documents is not null
            if(this.document==null)
                return;
            //sincronize document
            synchronized (this.document){
                try{
                    //normalize document
                    this.document.normalizeDocument();
                    //get a document documentSource object out of the document
                    DOMSource documentSource                = new DOMSource(this.document);
                    //create the file output stream
                    FileOutputStream fileOutputStream       = new FileOutputStream( this.file);
                    //create the output stream writer
                    OutputStreamWriter outputStreamWriter   = new OutputStreamWriter(fileOutputStream);
                    //create the stream streamResult out to the file Stream
                    StreamResult streamResult               = new StreamResult(outputStreamWriter);
                    //performe the trasformation
                    transformer.transform(documentSource, streamResult);
                    //clean up
                    outputStreamWriter.close();
                    outputStreamWriter = null;
                    fileOutputStream.close();
                    fileOutputStream = null;
                    documentSource = null;
                } catch (TransformerConfigurationException tcex) {
                    // Error generated by the parser
                    // Log Error
                    this.logger.logException(this, "errors.storage.xml.saveXMLRepositoryFile", true, tcex);
                } catch (TransformerException tex) {
                    // Error generated by the parser
                    // Log Error
                    this.logger.logException(this, "errors.storage.xml.saveXMLRepositoryFile", true, tex);
                } catch (Exception ex) {
                    // Unknown error
                    // Log Error
                    this.logger.logException(this, "errors.storage.xml.saveXMLRepositoryFile", true, ex);
        }

    I have an rtf template which is used to print output in pdf format. I have a table which has many rows which displays data for each record. In order to avoid breaking the page in between the rows of a record , i have added an outer table with single row and column and pasted the data table inside it and changed the row property of outer table to 'Allow Rows to Break Across Pages' to unchecked. It works fine only if the first record set length does not exceed a full page. IF the first record expanded to more than one page, it leaves a blank page at the very first and start the record at the second page. Can you please advise how to solve this issue. Its very URGENT please..

  • Problem with multiple applications using one audio output

    Hey there, I'm having issues setting up my 5.1 headset seen here (http://www.sharkoon.com/?q=en/content/x-tatic-digital) to work with multiple applications.
    Right now I have audio streaming from a flash video, when I try run "$ speaker-test -c 6" I get the following error:
    speaker-test 1.0.25
    Playback device is default
    Stream parameters are 48000Hz, S16_LE, 6 channels
    Using 16 octaves of pink noise
    ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave
    Playback open error: -16,Device or resource busy
    If I try open another application which uses this device, the first application has its sound cut off.
    2 more things to note:
    - My preference for setup would be audio output through S/PDIF and input through USB, with the USB output disabled (To not waste system resources).
    - I unmuted all channels in ALSA, however when I ran the test only 2 channels seemed to be working (Front L&R), it may have been defaulting to the USB connection, in which case, that explains only 2 channels being in use, is there a method of setting the S/PDIF as default system wide?
    Thanks in advance for any help given!

    brebs wrote:It's put the comments on multiple lines - fix that.
    Woops, I guess my paste messed up, new .asoundrc: http://pastie.org/3706033
    I can run both at the same time, however I cannot hear any audio. Do I somehow have to change the default device, if so how can I do that?
    Edit:
    Restarted system now I get:
    speaker-test 1.0.25
    Playback device is default
    Stream parameters are 48000Hz, S16_LE, 2 channels
    Using 16 octaves of pink noise
    Rate set to 48000Hz (requested 48000Hz)
    Buffer size range from 2048 to 8192
    Period size range from 1024 to 1024
    Using max buffer size 8192
    Periods = 4
    was set period_size = 1024
    was set buffer_size = 8192
    0 - Front Left
    Segmentation fault
    (That's with both commands)
    EDIT 2:
    Interesting, apparently 2 audio streams are working, however the console thing still doesn't work..?
    EDIT 3:
    Didn't last long, now flash crashes and html 5 doesn't work -.-
    EDIT 4:
    Flash only works when other audio is active, however it has constant popping sound. I went through the system logs to get the errors of when flash crashes, it's audio crashing it, here's the error:
    Apr  1 02:04:15 localhost kernel: [ 7057.499787] AudioThread[6227]: segfault at 7f2e2f7a8008 ip 00007f2e413a2786 sp 00007f2e33614ae8 error 7 in libasound.so.2.0.0[7f2e4131e000+eb000]
    Last edited by B3NW (2012-04-01 01:11:04)

  • Bash script question, how do I create multiple directories on one line

    I am making a package for amavisd-new (yes I am aware that there is one in community but I can't say I like the way it is done).
    I have an install script from which I want to create multiple directories if they do not exist.
    So I want to create a directory /var/spool/amavis with subdirectories of var tmp virusmails spammassassin .
    I can't seem to be able to find a way to do this on one line.

    pelle.k wrote:
    peets wrote:Hehe because it's less typing!
    Good one!
    Also, it's by far the more dynamic method.
    If you want to get pedantic, it's also far less efficient in terms of execution time: each iteration of the loop forks a new process, whereas using a single mkdir command forks only once.  The "best" way is the curly-braces method demonstrated above by chimeric.

Maybe you are looking for

  • Here we go again - all pear-shaped and customer on the warpath...

    This customer of mine seems destined to suffer one disaster after another. This time, they ran out of space on the boot drive sometime last Friday night - this time for fairly reasonable reasons (although named.log was about 15Gb in size for some rea

  • Printing in ECC5 on a external ITS

    Hi, We are upgrading from 46C to ECC5. We still want to use the external ITS. Everything works fine except that the printing in the iTS does not work anymore. We are on ITS 620 and everything worked fine before. We use the new LPD1 device that ECC5 n

  • How to Retrcit user from accessing t.code mm03 by plant wise.

    Hi All, User1 should have access for materialA from mm03(Display mat) for plantA but not for plantB. what roles to be given to user1 in order to do this settings. Please reply. Regards in Advance, Aiella

  • History of transaction

    Hello all, I'm creating this thread on behalf of Shashank Shekhar. A billing is generated in our database which is 6 months old. We need to identify the terminal name, terminal ip and all ther related history records of the transaction that has been

  • Changing Default Button in Pop-Up Message When Deleting a Song

    When deleting a song from iTunes, a message pops up asking, "Do you want to move the selected songs to the Trash, or keep them in the iTunes Music folder?" The user has the option of selecting Cancel, Keep Files or Move to Trash. Keep Files is highli