|
Hi,
Ive actually solved the problem now - I ended up creating Custom Classes for the two database tables and writing out the xml using asp.net:
Imports System.Xml
Imports NWDAweb.Classes.newsStories
Public Class PlasmaThanks
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
Protected WithEvents XMLTextBox As System.Web.UI.WebControls.TextBox
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim newsStoryObjList As newsStoryObjList = New newsStoryObjList
Dim xmlDoc As XmlDocument = New XmlDocument
Dim menuElement As XmlElement = xmlDoc.CreateElement("menu")
xmlDoc.AppendChild(menuElement)
If newsStoryObjList.SelectAll("plasmaScreen = 1", "datePosted") Then
For Each newsStoryObj As newsStoryObj In newsStoryObjList
Dim storyElement As XmlElement = xmlDoc.CreateElement("story")
Dim titleElement As XmlElement = xmlDoc.CreateElement("title")
Dim bodyElement As XmlElement = xmlDoc.CreateElement("body")
titleElement.InnerText = Server.HtmlEncode(newsStoryObj.headline)
bodyElement.InnerText = StripHTML(Server.HtmlDecode(newsStoryObj.bodyCopy))
storyElement.AppendChild(titleElement)
storyElement.AppendChild(bodyElement)
menuElement.AppendChild(storyElement)
Next
XMLTextBox.Text = xmlDoc.InnerXml
XMLTextBox.Visible = False
Dim xmlStreamWriter As System.IO.StreamWriter = System.IO.File.CreateText(Server.MapPath("news.xml"))
Try
xmlStreamWriter.Write(xmlDoc.InnerXml.Replace("&", "&").Replace(vbCrLf & vbCrLf, vbCrLf))
xmlStreamWriter.Close()
Catch
End Try
End If
End Sub
Private Function StripHTML(ByVal strIn As String) As String
Dim pattern As String = "<[^>]*>"
Return System.Text.RegularExpressions.Regex.Replace(strIn, pattern, String.Empty)
End Function
End Class
But thanks for the response
|
|
|
|
|
Hie,
All I want to display what is on the XML put on the datagrid at the same time, want a delete hyperlink to delete my user.
How to do it?
The Edit or Add function can ignore it or the best is delete it.
Let's look at the coding.
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Page Language="VB" Inherits="System.Web.UI.Page" %>
<title>Delete User Account
dim gXmlfile as string = "~/data/Users.xml"
dim gXmlPath as string
' =================================
Sub Page_Load(Src As Object, E As EventArgs)
gxmlpath = server.mappath( gXmlfile ) 'file is in same folder as page
If Not (IsPostBack)
DataLoad("UserEmail")
End If
End Sub
' ========================================
Sub DataLoad(parmsort as string)
Dim ds As New DataSet
Dim FS As New FileStream(Server.MapPath(gXmlFile), FileMode.Open)
ds.ReadXml(FS)
' 02/14/02 pchu handle an empty file ---------------------------
if ds.tables.count = 0 then
ds.tables.add( MakeBooksTable() )
end if
trace.warn ( "rowcount1 = " , cstr(ds.Tables(0).rows.count ))
' 02/14/02 pchu ---------------------------
' Add code to sort the dataview if parmsort is present
'ok let's get fancy and insert a blank row at the top
dim sw1 as integer = 1
select case sw1
case 1
dim dr as datarow = ds.Tables(0).newrow()
'put something in the first column ISBN
dr("UserEmail") = " Add UserEmail"
ds.Tables(0).rows.insertat(dr, 0)
trace.warn ( "rowcount2 = " , cstr(ds.Tables(0).rows.count ))
end select
'create dv and bind it to datagrid
dim dv as dataview
dv = new DataView(ds.Tables(0))
if parmsort.length > 0 then
dv.sort = parmsort
end if
MyDataGrid.DataSource = dv
'old MyDataGrid.DataSource = new DataView(ds.Tables(0))
' 02/14/02 pchu ---------------------------
MyDataGrid.DataBind()
FS.close()
END SUB
' ========================================
Sub DataSort(Src As Object, E As DataGridSortCommandEventArgs)
' Bug if we sort, then Edit Item Becomes Wrong
IF MyDataGrid.EditItemIndex=-1 THEN
DataLoad(e.sortexpression)
ELSE
response.write ("Can't sort until editing is done!")
END IF
End Sub
Sub DataDelete(Sender As Object, E As DataGridCommandEventArgs)
dim deletekey as string
If MyDataGrid.EditItemIndex=-1 Then
deletekey=MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))
response.write ("Delete completed for key = " & deletekey)
Else
response.write ("Can't delete until editing is done!")
End If
'' Dim currentRow As Integer = e.Item.DataSetIndex
Dim currentRow As Integer = e.Item.itemindex
'02/16/02 BugFix: because the datagrid has an insert row which is NOT in the
' in the dataset table, we have to subtract one to compensate for the that fact
currentrow = currentrow - 1 'bug fix: subtract 1 because the grid has a insert row
trace.warn (" current row to delete ", cstr(currentrow) )
' reload the XML file into a dataset
Dim ds As New DataSet()
ds.ReadXml(Server.MapPath(gXmlFile))
' get a reference to this row of data
Dim row As DataRow = ds.Tables(0).Rows( currentrow )
row.delete() '-- kill this row in the dataset (disabled for example)
' save the updated dataset to the XML file
ds.WriteXml(Server.MapPath(gXmlFile))
mydatagrid.EditItemIndex = -1 'exit delete mode
dataload("") ' redisplay and rebind datagrid
END SUB
Sub DataEdit(Sender As Object, E As DataGridCommandEventArgs)
DIM editkey as string
trace.warn ("e.item.itemindex = ", cstr(e.item.itemindex) )
MyDataGrid.EditItemIndex = Cint(E.Item.ItemIndex )
editkey=MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))
trace.warn ("page.aspx", "To Be Edited" & editkey)
SetEditMode( "on" )
DataLoad("")
End Sub
' ===================================
public sub dg_itemcreated ( sender as object, e as datagriditemeventargs )
if e.item.itemindex = 0 then 'first row
dim lbDelete as linkbutton = e.item.cells(0).controls(0)
trace.warn ("page.aspx", "lbDelete = " & lbDelete.text )
if lbDelete.text = "Delete User" then
lbDelete.text = ""
end if
end if
if e.item.itemindex > 0 then 'first row
select case e.item.itemtype
case listitemtype.item
dim mydeletebutton as tablecell
mydeletebutton = e.item.cells(0)
mydeletebutton.attributes.add("onclick", _
"return confirm('Are you sure you want to Delete?');" )
case listitemtype.alternatingitem
dim mydeletebutton as tablecell
mydeletebutton = e.item.cells(0)
mydeletebutton.attributes.add("onclick", _
"return confirm('Are you sure you want to Delete?');" )
end select
end if
end sub
' =========================
Private Function MakeUserTable() As DataTable
' Create a new DataTable titled 'Login.'
Dim theTable As DataTable = new DataTable("Login")
' Add two column objects to the table.
Dim theColumn1 As DataColumn = new DataColumn()
theColumn1.DataType = System.Type.GetType("System.String")
theColumn1.ColumnName = "UserEmail"
theTable.Columns.Add(theColumn1)
Dim theColumn2 As DataColumn = new DataColumn()
theColumn2.DataType = System.Type.GetType("System.String")
theColumn2.ColumnName = "UserPassword"
theTable.Columns.Add(theColumn2)
' Create an array for DataColumn objects.
Dim keys(0) As DataColumn
keys(0) = theColumn1
theTable.PrimaryKey = keys
' Return the new DataTable.
MakeUserTable = theTable
End Function
Delete User Account
<asp:datagrid id="MyDataGrid" style="Z-INDEX: 101; LEFT: 96px; POSITION: absolute; TOP: 56px"
="" runat="server" onitemcreated="dg_itemcreated" font-names="Verdana" headerstyle-font-size="10pt" headerstyle-backcolor="lightblue" font-size="8pt" font-name="Verdana" cellpadding="3" bordercolor="Black" backcolor="White" datakeyfield="isbn" ondeletecommand="DataDelete" allowsorting="True" width="400px" height="56px">
<headerstyle font-size="10pt" backcolor="LightBlue">
<columns>
<asp:buttoncolumn text="Delete User" commandname="mydeletebutton">
-------------------------------------------------------------------------
Users.xml file
<login>
<users>
<useremail>smurf@hotmail.com
<userpassword>CC0C3DBD8A231B92307C537673CFB26BDB24B421
<users>
<useremail>Duncan@yahoo.com
<userpassword>A9C53C9934EF3B01D0873BF3C6A9B291749A6454
<users>
<useremail>james@home.com
<userpassword>EB01D8F828A6C9A20BE4534E72E049AAF41503DF
Worried,
|
|
|
|
|
I have been working with XML for a while and quite often, I need to write navigation functions to search for a particular DOM model, such as find a book with a particular keyword but the publisher has to be somePublishName, plus the price of the book cannot be hight than $50.00, etc. The code to finish this task is somehow quite alike and tedious, I was just wondering if there is any tool to help on this part? For example, what about the TreeWalker thing with a NodeFilter? anyone heard of this and had some experience with this? Basically the searching in the XML file is very tedious and somewhat repeatable, any tools for this.
|
|
|
|
|
If u r looking for tools, u can use xmlspy.
I guess there is a free version also.
cool man
|
|
|
|
|
Hi,
I have a XML file which needs to be first validated using a DTD and then parsed to get values & properties associated with tags.
I am using Visual Studio's VC++ 6.0 to write my code. Is anyone aware of any reference or tutorial which would help me learn the same.
Thanks You!!
Regards
|
|
|
|
|
|
this is a piece of the xsl i use:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:output omit-xml-declaration="no" method="xml" indent="yes" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />
...
<input type="hidden" name="projectcode">
<xsl:attribute name="value">
<xsl:value-of select="../PROJECTCODE"/>
</xsl:attribute>
</input>
...
but when i render the xml using System.Xml.Xsl.XslTransform, the result is not valid xhtml. The hidden input is generated as:
<input type="hidden" name="projectcode" value="123"></input>
in stead of:
<input type="hidden" name="projectcode" value="123" />
does anyone have any idea what i am doing wrong??
|
|
|
|
|
Use the inline syntax for your attribute then you can have a closed tag element.
|
|
|
|
|
Thanks Chris!!
That did the trick!!
|
|
|
|
|
Hello all,
I am processing an XML file section appropriately (Individuals) . I have added elements (the Numbers section) to the XML File.
Below is the XML File Layout:
<Metrics>
<Numbers>
<Possible>13</Possible>
<Fail>0</Fail>
<Pass>7</Pass>
<Blocked>0</Blocked>
<NotRun>2</NotRun>
<TestBridgeID>43</TestBridgeID>
<VersionID>14</VersionID>
<Verified>0</Verified>
<Errors>4</Errors>
<Deleted>0</Deleted>
<RunDate>7/7/2004</RunDate>
</Numbers>
<Individuals>
<MultiLevelID>820</MultiLevelID>
<UIValues>
<Tab>Finishing</Tab>
<Control>Landscape</Control>
<Setting>ON</Setting>
<Disposition>1</Disposition>
<Reason>12</Reason>
</UIValues>
<UIValues>
<Tab>Finishing</Tab>
<Control>Landscape</Control>
<Setting>ON</Setting>
<Disposition>1</Disposition>
<Reason>12</Reason>
</UIValues>
</Individuals>
<Individuals>
etc. etc. etc.
Here is my code for processing the Individuals section.
private void ReadIndividualUI()
{
//Create a resolver with the necessary credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
NetworkCredential nc = new NetworkCredential(ConfigurationSettings.AppSettings ["SecureLogin"], ConfigurationSettings.AppSettings["SecurePassword"]);
resolver.Credentials = nc;
// Get a Stream object containing the XML file.
Uri myUri = new Uri("http://Benningfield1/DataSetTest/SwattReporta.xml");
Stream s = (Stream)resolver.GetEntity(myUri, null, typeof(Stream));
// Construct a reader using the Stream object.
XmlTextReader xmlReader = new XmlTextReader(s);
//Process XML File accordingly
while(xmlReader.Read())
{
//Perform appropriate processing
}
Here is my pseudocode for what I need to do next.
Go To The Numbers element
Pull all values (from Possible element, FAil element etc.) into a memory storage area
Then process values accordingly
What is the best way to mesh what I want to do in Pseudocode with the current ReadIndividualUI() method functionality?
TYIA,
lonelobo
|
|
|
|
|
Is it possible to evaluate XPath expression whose return type is not a nodeset (non location expressions) on Windows CE platform?
Igor
|
|
|
|
|
Can any body plz favor me with the regular expression of Xml document?
|
|
|
|
|
Hi Seekhtar
I really cann't understand your request ..
what do u mean by "regular expression of Xml document" ?
May be I could help u
Good Luck
|
|
|
|
|
Although there does not seem to be too much traffic in here I'll give it a try anyway...
I would like to be able to merge two XML documents, in such a manner that one will override the other. I.e., there will be a "global" XML file that contains some generic data, and then a "local" XML file that contains data that overrides data found in the global file. The local file does not have to contain the exact same number of nodes as the global one, i.e. it may only contain the nodes that we are interested in overriding.
You may ask yourself "how can this be helpful?", one example could be a global file that contains various settings that are used in an application, including text strings that will be visible to the user, and then a local file that contains translation of these visible text strings to some other languge, but otherwise does not change the settings/data in any way. In this way it will be easy to localise this file (we might want to be able to translate into many languages) without having to maintain multiple copies of the settings file - one for each language.
What I'm curious about is if there is a simple way to accomplish this through any known tools. The overhead should preferably be small, i.e. I don't want to be forced to install some massive Java libraries for this task alone . The code we're currently using to load/save XML files uses the Microsoft XML Parser so anything that's available through that tool is OK. I'm also willing to take a look at some .NET components if they do the job nicely, since this code will be used in an environment that ensures that the .NET framework has been installed.
Mind you that there are some obstacles on the way, for instance if the files in question were to store a list of books (classic example) and we would like to display the name of each book in the correct language, then we could create two files:
global.xml:
<books>
<book id="1">
<name>Some book</name>
<author>John Doe</author>
</book>
<book id="2">
<name>Another book</name>
<author>Susanne Smith</author>
</book>
</books>
local.xml ( book names have been translated into Icelandic ) :
<books>
<book id="1">
<name>Einhver bók</name>
</book>
<book id="2">
<name>Einhver önnur bók</name>
</book>
</books>
where the local.xml file does not want to mess with the author names, and it must override the correct bookname based on the id's. Note that under some circumstances, xml nodes equivalent to the <book> node might contain more attributes (not just the "id" attribute), and the unique attribute isn't necessarily called "id".
So does anyone have a *simple* solution to this problem? Any pointers would be very much welcome.
Best regards,
Daniel
|
|
|
|
|
Yes it is possible, I have worked on many a project where xml files are merged.
Unfortunatly I don't think there is any generic tool that will just do it for you, they way I have seen it done, is that the global xml file is loaded into the dom using MSXML, and the local file is loaded into a seperate dom.
Then for each node in the local file, a select is run against the global dom, to see if that node already exists. If it does the value is either replaced if the node does not exist then it is added into the dom.
All of this can be done using microsofts MSXML, just means writing some code yourself.
|
|
|
|
|
Thanks for your reply, writing code that uses the MSXML DOM is exactly what I have done, I was only curious if maybe I had reinvented the wheel
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
The merging of two xml documents can be more easily and elegantly performed by using xslt. Here is a link that implements the same beautifully.
http://www.informatik.hu-berlin.de/~obecker/XSLT/#merge
Think of it as evolution in action
|
|
|
|
|
hai philip,
I have been repeatedly getting the above stated error as
microsoft vbscript runtime error '800a01a8' object required: objNode
I am calling XML,XSLT files from my ASP page.
whenever i am using selectsinglenode() method. i am getting this error.
please help me. My entire project has been stalled due to this error.
my xslt and xml files are good and are without any bugs
my asp page is as follows.
<%Response.Buffer = true
Function viewdetail(strXMLFile, strXSLFile, strID)
'Declare local variables
Dim objXML
Dim objXMLNode
Dim objXSL
'Instantiate the XMLDOM Object that will hold the XML file.
set objXML = Server.CreateObject("MSXML2.DOMDocument.4.0")
'Turn off asyncronous file loading.
objXML.validateOnParse=true
objXML.async = false
'Load the XML file.
objXML.load(strXMLFile)
'set objXMLNode = objXML.selectsingleNode("xml/data/row")
'Get the XML record that you wish to view by calling the
'SelectSingleNode method and passing in the e-mail address of the
'contact.
'Instantiate the XMLDOM Object that will hold the XSL file.
set objXSL = Server.CreateObject("MSXML2.DOMDocument.4.0")
'Turn off asyncronous file loading.
objXSL.async = false
'Load the XSL file.
objXSL.load(strXSLFile)
Response.Write(objNode.transformNode(objXSL))
'Use the "transformNode" method of the XMLDOM to apply the XSL
'stylesheet to the XML document. Then the output is written to the
'client.
End Function
strID=Request.QueryString("au_id")
viewdetail server.MapPath("data.xml"),server.MapPath("adoxsltdup1.xslt"),strID
%>
with regards,
chaitanya
many thanks to those u solve my problem
|
|
|
|
|
hai philip,
I have been repeatedly getting the above stated error as
microsoft vbscript runtime error '800a01a8' object required: objNode
I am calling XML,XSLT files from my ASP page.
whenever i am using selectsinglenode() method. i am getting this error.
please help me. My entire project has been stalled due to this error.
my xslt and xml files are good and are without any bugs
my asp page is as follows.
<%Response.Buffer = true
Function viewdetail(strXMLFile, strXSLFile, strID)
'Declare local variables
Dim objXML
Dim objXMLNode
Dim objXSL
'Instantiate the XMLDOM Object that will hold the XML file.
set objXML = Server.CreateObject("MSXML2.DOMDocument.4.0")
'Turn off asyncronous file loading.
objXML.validateOnParse=true
objXML.async = false
'Load the XML file.
objXML.load(strXMLFile)
'set objXMLNode = objXML.selectsingleNode("xml/data/row")
'Get the XML record that you wish to view by calling the
'SelectSingleNode method and passing in the e-mail address of the
'contact.
'Instantiate the XMLDOM Object that will hold the XSL file.
set objXSL = Server.CreateObject("MSXML2.DOMDocument.4.0")
'Turn off asyncronous file loading.
objXSL.async = false
'Load the XSL file.
objXSL.load(strXSLFile)
Response.Write(objNode.transformNode(objXSL))
'Use the "transformNode" method of the XMLDOM to apply the XSL
'stylesheet to the XML document. Then the output is written to the
'client.
End Function
strID=Request.QueryString("au_id")
viewdetail server.MapPath("data.xml"),server.MapPath("adoxsltdup1.xslt"),strID
%>
with regards,
chaitanya
|
|
|
|
|
I need to feed records one at a time from SQL server to a vendors SOAP API and also be able to receice a record back as a seperate process via SOAP and place it into a different SQL table. The vendor transmitts an account number to me that then becomes part of the filter for what information I must send to them.
TO ME:
Vendor - SOAP - SQL Account Table
SQL Detail Table - SOAP - Vendor
...I think that's generic enough
Any ideas on the best way to accomplish this? Is a web service the right solution? I am looking to only use T-SQL and C#.
Thanks in advance for any help!
Craig
|
|
|
|
|
Im working on this program, and for some reason, I keep getting this error, but I dont understand how to fix it.
Here's the error:
A name was started with an invalid character. Error processing resource 'file:///C:/Documents and Settings/omar/Desktop/stp2.xml'. Line 2, Position 19
------------------^
and heres a copy of my code:
http://sourcepost.sytes.net/sourceview.aspx?source_id=15819
please help, thanks!
|
|
|
|
|
Hi osal ..
your problem - I think -
is, that you wrote a comment with a wrong syntax
so the right statement is like this ...
Good Luck
plz if I where wrong tell me the right statement after that..
|
|
|
|
|
Anyone available to help me out..it's a XML and XSL assignment..!! uregntly needed!!
|
|
|
|
|
|
hi
i am writing an application which maintains records of several clients. Each client has different settings. This is maintained in a XML file. When the user wants to update the data of a particular client changes have for that client.
this is what my XML document looks like.
<?xml version="1.0" encoding="UTF-8"?>
<config>
<client name="Cadbury">
<mcastg>222.23.342.1</mcastg>
<port>2222</port>
<path>c:\</path>
<repeat>4</repeat>
<spawn>4</spawn>
<ttl />
<profile>Custom</profile>
<custom>
<bw>1200</bw>
<dgsize>1024</dgsize>
</custom>
</client>
<client name="dabur">
<mcastg>222.23.432.23</mcastg>
<port>3333</port>
<path>d:\</path>
<repeat>5</repeat>
<spawn>5</spawn>
<ttl>4</ttl>
<profile>High</profile>
<custom>
<bw />
<dgsize />
</custom>
</client>
<client name="Vineet Inc">
<mcastg>222.23.43.4323</mcastg>
<port>5555</port>
<path>e:\</path>
<repeat>10</repeat>
<spawn>1</spawn>
<ttl>4</ttl>
<profile>Low</profile>
<custom>
<bw />
<dgsize />
</custom>
</client>
<client name="ICICI">
<mcastg>223.533.456.234</mcastg>
<port>54334</port>
<path>e:\hello</path>
<repeat>10</repeat>
<spawn>45</spawn>
<ttl>4</ttl>
<profile>Low</profile>
<custom>
<bw />
<dgsize />
</custom>
</client>
<client name="Vikram">
<mcastg>223.533.456.234</mcastg>
<port>5433</port>
<path>d:\vineet</path>
<repeat>10</repeat>
<spawn>45</spawn>
<ttl>4</ttl>
<profile>High</profile>
<custom>
<bw />
<dgsize />
</custom>
</client>
</config>
say i want to edit the settings for ICICI, how do i do from within the executing program. please give proper code.
Thanks
|
|
|
|