Jump to content


Photo

Trabalhando Com Xml


  • Faça o login para participar
12 replies to this topic

#1 MACUL

MACUL

    Doutor

  • Usuários
  • 770 posts
  • Sexo:Masculino
  • Localidade:SP

Posted 14/04/2004, 12:58

Simples
Dim doc As XmlDocument = New XmlDocument()

doc.Load(Server.MapPath("ARQUIVO.xml"))

doc.GetElementsByTagName("NOMEDONODE").Item(IDDONODEPARAOXML).InnerText()


IDDONODEPARAOXML = começa em zero

se quiser saber quantos tem :

Dim root As XmlElement = doc.DocumentElement
root.ChildNodes.Count()


XML + Repeater

Página ASPX
<form id="Form1" method="post" runat="server">
ID :
<asp:TextBox id="TxtId" runat="server" AutoPostBack="True" />
<asp:Repeater id="ItemAcervoRepeater" runat="server">
<HeaderTemplate>
<h3>Item Acervo</h3>
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "titulo") %>
</ItemTemplate>
<FooterTemplate>
<hr>
</FooterTemplate>
</asp:Repeater>
</form>

Página ASPX.VB
Imports System.Xml

'Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Le o arquivo XML em um XmlDataDocument assim podemos acessá-lo via DataSet
Dim myXmlDataDocument As New XmlDataDocument()
myXmlDataDocument.DataSet.DataSetName = "DSItemAcervo"
myXmlDataDocument.DataSet.ReadXmlSchema(strXmlSchema)
myXmlDataDocument.Load(strXmlDocument)

Dim ItemAcervoTable As DataTable
ItemAcervoTable = myXmlDataDocument.DataSet.Tables("ItemAcervoRef")

'vincula a fonte de dados ao controle repeater
ItemAcervoRepeater.DataSource = ItemAcervoTable
ItemAcervoRepeater.DataBind()

End Sub

Demonstrando Linhas e Colunas do XML
Imports System.Xml

  Dim ds As New DataSet()
       ds.ReadXml(Server.MapPath("../temp/ConfigNivelAcesso.xml"))

       Dim dc As DataColumn
       For Each dc In ds.Tables(0).Columns
           LblMsg.Text += "<br>" & dc.ColumnName
       Next

       LblMsg.Text += "<br><br><br>"

       'Verificando as linhas existentes 
       Dim dr As DataRow
       For Each dr In ds.Tables(0).Rows
           Dim i As Integer
           For i = 0 To ds.Tables(0).Columns.Count - 1
               LblMsg.Text += "<br>" & dr(i)
           Next
       Next

***********************************************
Public Function Chamado(ByVal strArqXml As String) As String
		Dim ds As System.Data.DataSet
		Dim intTable As Integer
		Dim intRows As Integer
		Dim intCols As Integer
		Dim strNometabela As String
		Dim strCampo As String
		Dim strCampoValor As String
		Dim strErro As String = ""

		ds = FnStrXmlToDataset(strArqXml)	   'Converte String 
	   
		For intTable = 0 To ds.Tables.Count - 1
			strNometabela = ds.Tables(intTable).TableName
			For intRows = 0 To ds.Tables(intTable).Rows.Count - 1
				For intCols = 0 To ds.Tables(intTable).Columns.Count - 1
					strCampo = ds.Tables(intTable).Columns(intCols).ColumnName
					strCampoValor = ds.Tables(intTable).Rows(intRows).Item(strCampo)

				Next
			Next
		Next
End Function

   'Criado Dia 14/01/2008 Por Tiago MACUL
	'Função converte uma variável com conteúdo em XML para um DATASET
	''' <summary>
	'''converte uma variável com conteúdo em XML para um DATASET
	''' </summary>
	Public Function FnStrXmlToDataset(ByVal strArqXml As String)
		Dim xmlSR As System.IO.StringReader = New System.IO.StringReader(strArqXml)
		Dim ds As New Data.DataSet
		Try
			ds.ReadXml(xmlSR) ' , Data.XmlReadMode.IgnoreSchema)
		Catch ex As Exception
			'EscreveLog("BancoDados.FnStrXmlToDataset", Err.Number, ex.Message)
		End Try
		Return ds
	End Function

LINKs

Página dinâmica atualiza usando XMLHTTP
http://www.thescript...read484515.html

http://www.xmlforasp.net/

Edição feita por: MACUL, 19/03/2008, 16:48.

*************** M ** A ** C ** U ** L ***************

*************************************************

#2 Tx.NET

Tx.NET

    || ||||||| ||| ||||||||

  • Banidos
  • PipPipPipPipPipPipPip
  • 619 posts
  • Sexo:Não informado

Posted 30/08/2004, 09:37

muito bom este tópico!

(y) (y) (y) (y)
flws. (y)
> ls -la
-rwxr-xr-- 1 fmaynnard user 9666 nov 28 00:00 hell

> shutdown -h now

#3 eric_flash

eric_flash

    Novato no fórum

  • Usuários
  • 2 posts
  • Sexo:Não informado

Posted 01/11/2006, 09:43

Desculpe, mas ainda não consegui entender direito, vamos supor que eu tenha o seguinte xml:

<?xml version="1.0" encoding="iso-8859-1"?>
<pessoas>

<pessoa>
<nome>Felipe</nome>
<idade>22 anos</idade>
</pessoa>

<pessoa>
<nome>Fábio</nome>
<idade>25 anos</idade>
</pessoa>

</pessoas>

Como faria para selecionar e escrever no browser apenas os nomes?

Usando VB.net

#4 MACUL

MACUL

    Doutor

  • Usuários
  • 770 posts
  • Sexo:Masculino
  • Localidade:SP

Posted 01/11/2006, 22:52

veja se melhora
http://www.macul.eti...esconectado.htm
*************** M ** A ** C ** U ** L ***************

*************************************************

#5 MACUL

MACUL

    Doutor

  • Usuários
  • 770 posts
  • Sexo:Masculino
  • Localidade:SP

Posted 06/11/2006, 09:09

XML Developer Center
http://msdn.microsoft.com/XML/

XML Downloads
http://msdn.microsof...ds/default.aspx

XML Code Samples
http://msdn.microsof...es/default.aspx
*************** M ** A ** C ** U ** L ***************

*************************************************

#6 eric_flash

eric_flash

    Novato no fórum

  • Usuários
  • 2 posts
  • Sexo:Não informado

Posted 06/11/2006, 09:17

Valeu MACUL!

Vou dar uma estudada, qualquer coisa posto aqui!

#7 MACUL

MACUL

    Doutor

  • Usuários
  • 770 posts
  • Sexo:Masculino
  • Localidade:SP

Posted 14/01/2008, 17:31

Crie essa função pode auxiliar quem precisa
converte uma string xml para um DataSet
Private Function FnStrXmlToDataset(ByVal strArqXml As String)
		Dim xmlSR As System.IO.StringReader = New System.IO.StringReader(strArqXml)
		Dim ds As New Data.DataSet
		ds.ReadXml(xmlSR) 
		Return ds
	End Function

Segue + algumas referências
http://www.aspneti.c...digo 300,0.aspx
http://msdn2.microso...y/fx29c3yd.aspx
http://samples.gotdo...SetXMLData.aspx
*************** M ** A ** C ** U ** L ***************

*************************************************

#8 MACUL

MACUL

    Doutor

  • Usuários
  • 770 posts
  • Sexo:Masculino
  • Localidade:SP

Posted 18/01/2008, 08:52

Função para ler XML em variável texto/String e retornar em um DataRow, com certeza terá que adaptar para utilizar.
Com a Segunda função você poderá saber como fazer pois demonstra na tela.
Public Function LerXML(ByVal strXML As String) As Data.DataRow

		' Proc que procura no xml por determinado objetos , passando pra respectivas variaveis
		Dim ds As Data.DataSet
		Dim dt As New System.Data.DataTable
		Dim dr As System.Data.DataRow

		dr = dt.NewRow
		ds = FnStrXmlToDataset(strXML)

		dr.Table.NewRow()

		Dim sNome As String = ""
		Dim intTables As Integer
		Dim intRows As Integer = 0

		For intTables = 0 To ds.Tables.Count - 1		   
						sNome = ds.Tables(intTables).Rows(intRows).Item("AttrName")
						dr.Table.Columns.Add(sNome)
						dr(sNome) = ds.Tables(intTables).Rows(intRows).Item("AttrValue")
		Next

		Return dr
	End Function

Public Function LerXML(ByVal strXML As String) As String
		Dim strRet As String = ""
		' Proc que procura no xml por determinado objetos , passando pra respectivas variaveis
		Dim ds As Data.DataSet

		ds = FnStrXmlToDataset(strXML)

		Dim sNome As String = ""
		Dim intTables As Integer = 0
		Dim intRows As Integer = 0
		Dim intCols As Integer = 0

		For intTables = 0 To ds.Tables.Count - 1
			strRet += " table = " & ds.Tables(intTables).TableName & " "
			For intRows = 0 To ds.Tables(intTables).Rows.Count - 1
				For intCols = 0 To ds.Tables(intTables).Columns.Count - 1
					strRet += " intCols(" & intCols & ") = " & ds.Tables(intTables).Rows(intRows).Item(intCols) & " " & "<br>"
				Next
			Next
		Next
		Return strRet
	End Function
obs : Se tiver utilizando Windows Forms basta trocar o Response.Write para um label ou textbox

Escrevendo XML
Public Function WriteXml(ByVal dr As Data.DataRow) As String
		Dim strSaida As String
		'configurar  XML
		Dim settings As New System.Xml.XmlWriterSettings
		settings.Indent = True
		settings.IndentChars = " "
		settings.NewLineOnAttributes = False
		settings.OmitXmlDeclaration = False

		'criamos um StringBuilder e um XMLWriter
		Dim sb As New StringBuilder
		Dim tw As System.Xml.XmlWriter = System.Xml.XmlWriter.Create(sb, settings)

		With tw

			.WriteStartDocument()

			.WriteStartElement("MXINCINTERFACE")

			.WriteStartElement("Header")
			.WriteElementString("SenderID", "")
			.WriteElementString("CreationDateTime", "")
			.WriteElementString("RecipientID", "")
			.WriteElementString("MessageID", "")
			.WriteEndElement()  'Header

			.WriteStartElement("Content")
			.WriteStartElement("MXINCIDENT")

			.WriteStartElement("INCIDENT")
			.WriteElementString("TICKETID", dr.Item("zref_num"))
			.WriteEndElement() 'INCIDENT 

			.WriteEndElement() 'MXINCIDENT
			.WriteEndElement()  'Content


			.WriteEndElement()  'MXINCINTERFACE

			.Flush()
			.Close()
		End With
		strSaida = sb.ToString

		Return strSaida
	End Function

*************** M ** A ** C ** U ** L ***************

*************************************************

#9 MACUL

MACUL

    Doutor

  • Usuários
  • 770 posts
  • Sexo:Masculino
  • Localidade:SP

Posted 22/01/2008, 14:16

http://support.micro...om/kb/301282/pt
http://www.danielfon...inq-to-XML.aspx

Edição feita por: MACUL, 03/06/2009, 14:51.

*************** M ** A ** C ** U ** L ***************

*************************************************

#10 LarPhozyHah

LarPhozyHah

    Super Veterano

  • Usuários
  • 14515 posts
  • Sexo:Masculino
  • Localidade:San Miguel de Tucuman

Posted 02/10/2017, 23:43

Propecia Tadacip Zoloft Fast Delivery Effexor Online Without Prescription generic levitra shipped from usa Pharm Support Group Canada
com. loans no credit check It is possible to be approved for a rate that is higher than what is suggested by this chart.co.
Clomid Allergie Viagra Comprar Viagra Generico buy levitra generic online Amoxicillin Before Food Cout Levitra 10 Viagra Vs Cialis Sales
Nexium Online Pharmacy Canada Amoxicillin And Birth Control Pills Propecia Im Ausland Kaufen discount levitra canada Keflex Tablets Super Kamagra Schweiz
Usual Dosage For Keflex 500 Mg Ordina Kamagra A Buon Mercato viagra online prescription Venta De Viagra buy direct cod isotretinoin sotret in germany overseas Sefton Purchase Alli Online

#11 LarPhozyHah

LarPhozyHah

    Super Veterano

  • Usuários
  • 14515 posts
  • Sexo:Masculino
  • Localidade:San Miguel de Tucuman

Posted 14/10/2017, 08:00

Cialis 5mg Bestellen Cheapeast Generic Progesterone Best Website Worldwide On Line best price on levitra Amoxicillin How To Buy Best Buy Stendra No Prior Script El Paso
Cherche Viagra Ou Cialis cialis buy online Cialis (Tadalafil)No Presciption Needed Propecia Rogaine Hair Regrowth
Cytotec Pauvre Buy Propecia In Mexico cialis Cialis Napoli Prix Viagra Belgique Viagra Et Levitra
Chemical Properties Of Amoxicillin osu levitra comprar Buy Cheap Plavix discount worldwide fedex shipping isotretinoin pills
Como Comprar Viagra En Espana Amoxicillin Dog Farmcy On Line viagra Propecia Information Leaflet Jessica'S Pharmacy In Progreso Mexico Keflex To Treat Ear Infections

#12 LarPhozyHah

LarPhozyHah

    Super Veterano

  • Usuários
  • 14515 posts
  • Sexo:Masculino
  • Localidade:San Miguel de Tucuman

Posted 29/10/2017, 12:19

Determining Correct Amoxicillin Dosage viagra Buy Vigra
Wat Is Kamagra generic cialis Le Cialis Acheter Buy Sertraline Online Baclofene Protocole
Levitra Preise Deutschland levitra 20mg prix Propecia Temple Hair Loss Amoxicillin Skin Disorders Dosage Cialis Prix Andorre
Tadalafil 10mg Cheap Climen No Prescription Amoxicillin 93 3109 viagra online pharmacy Vimax
Cialis Generika Online Keflex Joint Swellings Pastillas Viagra Precio generic viagra Is Alli Available Benadryl And Amoxicillin Same Time
Achat Propranolol Afin Priligy buy cialis Canadian Pharmacy Mail Order Cialis Farmacias Online

#13 LarPhozyHah

LarPhozyHah

    Super Veterano

  • Usuários
  • 14515 posts
  • Sexo:Masculino
  • Localidade:San Miguel de Tucuman

Posted 17/11/2017, 00:53

Green Viagra Pills viagra Lasix Pay Online American Express
Avis Cialis 20 cialis Keflex Dental Infection Dapoxetina Precisa Receita Pharmacy Top Pills Coupons
Achat Kamagra Sur Internet Viagra Cost Per 100mg Pill viagra online pharmacy Cialis Para Comprar
Cialis Nebenwirkungen Durchfall Amoxicillin Metabolism viagra Cialis India Pharmacy Buy Allopurinol Without A Prescription Preise Viagra Cialis
Levaquin With Free Shipping Tadalafil Generique France cialis online Cephalexin Weight Gain




0 user(s) are reading this topic

0 membro(s), 0 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq