Results 1 to 4 of 4

Thread: [2008] Creating XML

  1. #1

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    [2008] Creating XML

    Guys, simple one, where am I going wrong with creating this xml???

    This is what I want.....
    Code:
    <0A0B1264510C0D23_15012009_status>
        <ptev_g01_01>
    	<ptev_g01_com>"testing comments"<\ptev_g01_com>
    	<ptev_g01_cat>"C"<\ptev_g01_cat>
    	<ptev_g01_vds>"53535353"<\ptev_g01_vd>
    	<ptev_g01_yesno>"Yes"<\ptev_g01_yesno>
        <\ptev_g01_01>
    This is what I'm getting....
    Code:
    <?xml version="1.0"?>
    <0A0B1264510C0D23_15012009_status>
      <ptev_g01_01 ptev_g01_com="testing comments" ptev_g01_cat="P" ptev_g01_vds="1234567" ptev_g01_yesno="Yes" />
      <ptev_g01_02 ptev_g01_com="" ptev_g01_cat="" ptev_g01_vds="" ptev_g01_yesno="" />
      <ptev_g01_03 ptev_g01_com="" ptev_g01_cat="" ptev_g01_vds="" ptev_g01_yesno="" />
      <ptev_g01_04 ptev_g01_com="" ptev_g01_cat="" ptev_g01_vds="" ptev_g01_yesno="" />
      <ptev_g01_05 ptev_g01_com="" ptev_g01_cat="" ptev_g01_vds="" ptev_g01_yesno="" />
    And heres the code that creates it...


    Code:
         ' Create the root node of a new XML document.
            Dim xml As New XmlDocument
            ' Use the XmlDeclaration class to place the
            ' <?xml version="1.0"?> declaration at the top of our XML file
            Dim dec As XmlDeclaration = xml.CreateXmlDeclaration("1.0", Nothing, Nothing)
            xml.AppendChild(dec)
    
            'Create root node
            xmls_parent = str_objectid & "_" & Replace(lbl_DateCompleted.Text, "/", "") & "_" & "status"
            Dim DocRoot As XmlElement = xml.CreateElement(xmls_parent)
            xml.AppendChild(DocRoot)
    
            Dim acp As AccordionPane
            For Each acp In accMain.Panes
    
                'get all question data and append to question node
                Dim QListview As ListView = TryCast(acp.FindControl("lstQuestions"), ListView)
                For Each itm As ListViewItem In QListview.Items
                    'Add a question child node
                    Dim question As XmlNode = xml.CreateElement("ptev_g" & Format(xml_section, "00").ToString & "_" & Format(xml_question, "00").ToString)
    
                    Dim Qcontrol As QuestionsControl = TryCast(itm.FindControl("customControl"), QuestionsControl)
                    Dim newAtt As XmlAttribute
    
                    newAtt = xml.CreateAttribute("ptev_g" & Format(xml_section, "00").ToString & "_com")
                    newAtt.Value = Qcontrol.QComment
                    question.Attributes.Append(newAtt)
    
                    newAtt = xml.CreateAttribute("ptev_g" & Format(xml_section, "00").ToString & "_cat")
                    newAtt.Value = Qcontrol.QCategory
                    question.Attributes.Append(newAtt)
    
                    newAtt = xml.CreateAttribute("ptev_g" & Format(xml_section, "00").ToString & "_vds")
                    newAtt.Value = Qcontrol.QVDSCode
                    question.Attributes.Append(newAtt)
    
                    newAtt = xml.CreateAttribute("ptev_g" & Format(xml_section, "00").ToString & "_yesno")
                    newAtt.Value = Qcontrol.QYesno
                    question.Attributes.Append(newAtt)
    
                    DocRoot.AppendChild(question)
    
                    xml_question = xml_question + 1
                Next
                xml_question = 1
                xml_section = xml_section + 1
            Next
    
            xml.Save("c:\PartEval.xml")
    Last edited by staticbob; Jan 15th, 2009 at 04:46 PM.
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2008] Creating XML

    you're getting everythign on one line because you're creating one node, then adding all the attributes to it....

    What you should be doing is creating new nodes instead of attributes, and adding them to the question node.

    -chris
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] Creating XML

    Rule of thumb... For each <element>, CreateElement. For each attribute="attribute", CreateAttribute.

    An attribute must belong to an element, of course.

  4. #4

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Re: [2008] Creating XML

    Thanks for the response guys...

    Got it, this works...

    Dim answer As XmlNode = xml.CreateElement("ptev_g" & Format(xml_section, "00").ToString & "_cat")
    answer.InnerText = Qcontrol.QCategory
    question.AppendChild(answer)
    Last edited by staticbob; Jan 15th, 2009 at 07:17 PM.
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width