|
-
Jan 15th, 2009, 04:34 PM
#1
Thread Starter
Fanatic Member
[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
-
Jan 15th, 2009, 04:42 PM
#2
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
-
Jan 15th, 2009, 05:05 PM
#3
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.
-
Jan 15th, 2009, 06:52 PM
#4
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|