Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 19, 2013 02:13 AM by Decker Dong - MSFT
Member
13 Points
25 Posts
Jan 17, 2013 08:31 AM|LINK
Hi All,
I am trying to create XML document using vb.net.
I am trying to create following xml document.
<?xml version="1.0" encoding="utf-8"?>
<artists>
<artist>
<full_name><![CDATA[Person Name]]></full_name>
<images>
<image>
<url><![CDATA[/images/artists/1250.png]]></url>
</image>
<videos>
<video>
<url><![CDATA[URL]]></url>
</video>
</artist>
</artists>
Following is the code i am using:
<WebMethod()> _
Public Function GetArtist(ByVal itemcode As String) As XmlDocument
con.Open()
myCmd = New SqlCommand("select * from Hal_Artists where ArtistCode = 'ABA'", con)
myCmd.CommandType = CommandType.Text
Dim doc As XmlDocument = New XmlDocument
Dim result As SqlDataReader = myCmd.ExecuteReader(CommandBehavior.CloseConnection)
If result.HasRows() Then
result.Read()
Dim docNode As XmlNode = doc.CreateXmlDeclaration("1.0", "UTF-8", Nothing)
doc.AppendChild(docNode)
Dim ArtistsNode As XmlNode = doc.CreateElement("Artists")
doc.AppendChild(ArtistsNode)
Dim ArtistNode As XmlNode = doc.CreateElement("Artist")
ArtistsNode.AppendChild(ArtistNode)
Dim ArtistFullName As XmlNode = doc.CreateElement("full_name")
ArtistFullName.InnerText = result("Name")
End If
Return doc
End Function
I am unable to add two artist(<artist>) in one <artists> block.
one more quetion ,how can add image block(<images>)?
If anyone could show me some code example that would be really useful.
Thanks in advance.
Jan 17, 2013 10:13 AM|LINK
Hello again,
i have manage to add the image block but no luck with multiple artist block.
please can someone help me
All-Star
118619 Points
18779 Posts
Jan 19, 2013 02:13 AM|LINK
tmukhtar but no luck with multiple artist block.
Hi,
You have to take a look at XmlDocument,that lets you do something supporting to create XmlElement……here's the sample for you to see to create a nest xml node:
Module Module1 Sub Main() Dim document As New XmlDocument 'Root element Dim root As XmlElement = document.CreateElement("articles") 'Sub element Dim item As XmlElement = document.CreateElement("article") 'Sub Sub element Dim sitem As XmlElement = document.CreateElement("fullname") Dim cdata As XmlCDataSection = document.CreateCDataSection("MyValueHere") sitem.AppendChild(cdata) item.AppendChild(sitem) root.AppendChild(item) document.AppendChild(root) document.Save("d:\\try.xml") Console.WriteLine("OK") End Sub End Module
tmukhtar
Member
13 Points
25 Posts
XML Document
Jan 17, 2013 08:31 AM|LINK
Hi All,
I am trying to create XML document using vb.net.
I am trying to create following xml document.
<?xml version="1.0" encoding="utf-8"?>
<artists>
<artist>
<full_name><![CDATA[Person Name]]></full_name>
<images>
<image>
<url><![CDATA[/images/artists/1250.png]]></url>
</image>
<images>
<videos>
<video>
<url><![CDATA[URL]]></url>
</video>
<videos>
</artist>
</artists>
Following is the code i am using:
<WebMethod()> _
Public Function GetArtist(ByVal itemcode As String) As XmlDocument
con.Open()
myCmd = New SqlCommand("select * from Hal_Artists where ArtistCode = 'ABA'", con)
myCmd.CommandType = CommandType.Text
Dim doc As XmlDocument = New XmlDocument
Dim result As SqlDataReader = myCmd.ExecuteReader(CommandBehavior.CloseConnection)
If result.HasRows() Then
result.Read()
Dim docNode As XmlNode = doc.CreateXmlDeclaration("1.0", "UTF-8", Nothing)
doc.AppendChild(docNode)
Dim ArtistsNode As XmlNode = doc.CreateElement("Artists")
doc.AppendChild(ArtistsNode)
Dim ArtistNode As XmlNode = doc.CreateElement("Artist")
ArtistsNode.AppendChild(ArtistNode)
Dim ArtistFullName As XmlNode = doc.CreateElement("full_name")
ArtistFullName.InnerText = result("Name")
End If
Return doc
End Function
I am unable to add two artist(<artist>) in one <artists> block.
one more quetion ,how can add image block(<images>)?
If anyone could show me some code example that would be really useful.
Thanks in advance.
tmukhtar
Member
13 Points
25 Posts
Re: XML Document
Jan 17, 2013 10:13 AM|LINK
Hello again,
i have manage to add the image block but no luck with multiple artist block.
please can someone help me
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: XML Document
Jan 19, 2013 02:13 AM|LINK
Hi,
You have to take a look at XmlDocument,that lets you do something supporting to create XmlElement……here's the sample for you to see to create a nest xml node: