|
A XML File is a plain text file... because this cannot be password protected. You can to cryptograph it with the classes of namespace "System.Security.Cryptography" in .Net Framework or CryptoAPI (in Win32 API)
Good Luck!
|
|
|
|
|
Hi Gurus!
I have the simplest xml document (d:\\book.xml):
<?xml version="1.0"?>
<Report>
...
</Report>
I've written the small program (inserting XSL reference in the prolog):
Dim xmlDoc,pi,ref
set xmlDoc = CreateObject ("Msxml.DOMDocument")
xmlDoc.async = false
xmlDoc.resolveExternals = false
xmlDoc.load ("d:\\book.xml")
ref="type=""text/xsl"" href=""mysheet.xsl"""
set pi = xmlDoc.createProcessingInstruction("xml-stylesheet",ref)
xmlDoc.insertBefore pi,xmlDoc.childNodes.item(1)
WScript.Echo(xmlDoc.xml)
It works fine!
Next, I tried to do the same using Microsoft Visual C++:
IXMLDOMDocumentPtr XmlDocPtr;
_bstr_t bstrXMLReport(_T("d:\\book.xml");
VARIANT_BOOL vtResult;
HRESULT hr = XmlDocPtr.CreateInstance(MSXML::CLSID_DOMDocument);
if (FAILED(hr))
{
AfxMessageBox("Failed to CreateInstance(CLSID_DOMDocument)");
return;
};
XmlDocPtr->async=FALSE;
XmlDocPtr->resolveExternals=FALSE;
vtResult=XmlDocPtr->load(bstrXMLReport);
if (vtResult == VARIANT_FALSE)
{
AfxMessageBox("Failed to load XML document");
return;
};
IXMLDOMProcessingInstructionPtr pi;
_bstr_t bstrTarget(_T("xml-stylesheet"));
_bstr_t bstrData(_T("type=\"text/xsl\" href=\"mysheet.xsl\""));
pi=XmlDocPtr->createProcessingInstruction(bstrTarget,bstrData);
BSTR qqq;
pi->get_xml(&qqq);
CComVariant varRef;
IXMLDOMNodePtr pFirst,pXMLNodeCur;
XmlDocPtr->childNodes->get_item(1,&pFirst);
varRef=pFirst;
try
{
XmlDocPtr->insertBefore(pi,t);
AfxMessageBox(XmlDocPtr->xml);
}
catch(_com_error &er)
{
TCHAR szErr[MAX_PATH];
memset(szErr,0,sizeof(szErr));
_tcscpy(szErr,(LPCTSTR)er.Description());
AfxMessageBox(szErr);
};
After that, I've got the exception "The parameter is incorrect."
Why? I suspect the incorrect usage of insertBefore method.
What should I do?
Yours sincerely,
Alex Bash
|
|
|
|
|
I have a XML File with 32000 records, about 5Mb size.
How I do to load this (very fast) in Windows Forms DataGrid?
In help of .Net SDK says what I need use a XMLTextReader, but it is slow for me...
Thanks for all
|
|
|
|
|
Have you tried loading the Xml file into a DataSet and assigning it to your grid's DataSource property?
DataSet ds = new DataSet();
ds.ReadXml(<<path to xml file>>);
grid.DataSource = ds;
|
|
|
|
|
What exactly are you wanting to do with this huge XML file? Try loading it into a dataset before loading it into the DataGrid.
Matthew R. Sannes
Docsoft
Technical Marketing Specialist
www.docsoft.com
msannes@docsoft.com
|
|
|
|
|
Well...
My ISP gives 150 MB space to files and 10 MB of Database (MSDE).
I have a "Holy Bible" database, what haves 6 MB...
How this database is read-only, I think what I can store it in a XML file and load-it when necessary... But this is very slow!!!
Any sugestion?
Thank you very much for your attention
|
|
|
|
|
If it's read only, load it into a global application DataSet in the web application startup, that way it'll be around across multiple sessions without the hit from loading a 6MB XML file every time you need to access the "database." You only load it once, when the application starts...
protected void Application_Start(Object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.Load(Server.MapPath("./db.xml"));
Application.Contents.Add("db") = ds;
}
To get it back, say to load up in a method in aspx code-behind page:
DataSet ds = (DataSet)Application.Contents["db"];
|
|
|
|
|
|
Hi Gurus!
How to programmaly update the prolog of existing XML document? (using MSXML)
I have the follows in the prolog:
I want to change from "style.css" to "style2.css". What should I do?
Yours sincerely,
Alex Bash
|
|
|
|
|
Sorry, my question is:
Hi Gurus!
How to programmaly update the prolog of existing XML document? (using MSXML)
I have the follows in the prolog:
<?xml-stylesheet href="/style.css" type="text/css">
I want to change from "style.css" to "style2.css". What should I do?
Yours sincerely,
Alex Bash
|
|
|
|
|
What version of MSXML are you using? And how are you planning on go about this application wise?
Matthew R. Sannes
Docsoft
Technical Marketing Specialist
www.docsoft.com
msannes@docsoft.com
|
|
|
|
|
I have an xml document with 3 topic elements: Topic1, Topic2, Topic3
I have an xsl stylesheet that has a topic template. I want to be able to select different combinations of topics using xpath and a parameter.
To select all topics I use this: Content/Topics/Topic
To select just Topic1, I use this: Content/Topics/Topic[@name='Topic1']
I have a param named MatchTopic and I want to select any combination of Topics, say Topic1 and Topic2 or Topic1 and Topic3 or Topic2 and Topic3.
I tried this:
<xsl:apply-templates select="Content/Topics/Topic[$MatchTopic]"/>
with the following param value:
<xsl:param name="MatchTopic">Content/Topics/Topic[@name='Product Updates' or @name='Management']</xsl:param>
and it doesn't work. Nothing I try works.
Is it possible to call this template and select any combination of topics using a parameter?
Thanks in advance.
|
|
|
|
|
yes, but you have to use an extension..
msxsl:node-set
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
I am trying to create an xml file from an xml file using vb.net and XmlTransform .
My xsl file has this line
xsl:output method="xml" version="1.0" encoding="UTF-8" cdata-section-elements="Column"
I want to wrap the data in the node Column in CDATA tags. This works in vbScript and tesing using XML Spy but in the asp.net page using XmlTransform the node does not get wrapped in CDATA Tags.
Any help would be great I am in a bind.
|
|
|
|
|
I'am quite new to XML in .NET and would appreciate some advice on the correct way to iterate through an XML document I have created like:
[XML DOC]
[OuterList]
[ListItem image="C:\pic1.wmf"]
[InnerList]
[Item Atr1="ABC" Atr2="DEF" Atr3="GHI"/]
[Item Atr1="123" Atr2="456" Atr3="789"/]
[/InnerList]
[/ListItem]
[ListItem image="C\pic2.wmf"/]
[InnerList]
[Item Atr1="ZYZ" Atr2="WVU" Atr3="TSR"/]
[/InnerList]
[/ListItem]
[/OuterList]
- note I have replaced the XML tags with []
I would only want to go to a specific item in the outerlist, and then read each item in its innerlist.
|
|
|
|
|
Learn a little about XPATH queries. The System.Xml.XmlDocument class supports a method, SelectSingleNode which you would use to get to the specific <OuterList> node. Am I correct in thinking you have some kind of identifier for your <OuterList> nodes? If you have an id attribute or something you could use SelectSingleNode to get the node with that specific id . For example, say you have your Xml doc with the <OuterList id="124">. You can get that node as follows:
XmlDocument doc = new XmlDocument();
doc.LoadXml([doc string here]);
XmlNode outerListNode = doc.SelectSingleNode("descendant::OuterList[@id='124']");
Once you have the node, you can further use SelectSingleNode to get another node underneath that you're interested in, such it's child <ListImage> element, e.g., XmlNode listImageNode = outerListNode.SelectSingleNode("descendant::ListItem") and grab the image attribute by listImageNode.Attributes["image"].Value -- of course, checking for null s and errors all the while -- Never forget error checking!
Alternatively, you can just iterate through the outerListNode.<a href="http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemxmlxmlnodeclasschildnodestopic.asp?frame=true" target="_blank">ChildNodes</a> and handle it as you encounter them (in a foreach loop.) This approach, however, is overkill for your case.
Another alternative is to create a class structure using Xml Serialization and the XmlSerializer. This way you can handle the <OuterList> items as part of an object collection in your document representation class.
There are several ways to approach this using .NET. I suggest you peruse the MSDN dox, as well as articles here.
Good Luck!
|
|
|
|
|
Hi..
is it valid to nest an XML tag within a tag of the same type ?
like this :
<Drive name="C">
<Folder name="folder1">
<Folder name="New Folder"/>
</Folder>
</Drive>
|
|
|
|
|
You're not really nesting. Nesting would have a <Folder> or <Drive> element within another <Folder> or <Drive> element.
Oh yeah, yes it's legal as long as it's well-formed:
<drive dev="/dev/hda1">
<folder name="bin"/>
<folder name="usr">
<folder name="bin"/>
<folder name="sbin"/>
<folder name="src"/>
<folder name="darwin" link="true"/>
<folder name="include"/>
<folder name="linux" link="true"/>
</folder>
</folder>
<folder name="sbin"/>
</drive>
The W3C says, "A consequence of well-formedness in general entities is that the logical and physical structures in an XML document are properly nested; no start-tag, end-tag, empty-element tag, element, comment, processing instruction, character reference, or entity reference can begin in one entity and end in another."
|
|
|
|
|
I'm reading xml from SQL server with VB.net using an XSD schema file. I have the code working fine, but I'd now like to change the code from reading a file on disk to reading the schema from the file as an embedded resource. Here's my code, what do I need to change??
<br />
Dim conString As String = "MyConnectionString"<br />
Dim strm As Stream<br />
Dim strmReader As StreamReader<br />
Dim cmd As New SqlXmlCommand(conString)<br />
Dim xmlDoc As New XmlDocument<br />
Dim strXML As String<br />
<br />
With cmd<br />
.CommandText = "MyXPath"<br />
.CommandType = SqlXmlCommandType.XPath<br />
.SchemaPath = "C:\MySchemaFile.xsd" '**I want this to be embedded!!**<br />
strm = .ExecuteStream<br />
End With<br />
<br />
strmReader = New StreamReader(strm)<br />
strXML = strmReader.ReadToEnd<br />
xmlDoc.LoadXml(strXML)<br />
Like I said, the above code works fine, but I don't want a physical file location.
Thanks!!!
-Michael
|
|
|
|
|
Add the XSD to the project, change it's build type to Embedded Resource. You'll use the Namespace to get at it. For example, if your assembly default namespace is MyDataAccess , the resource base name will be MyDataAccess.MySchemaFile.xsd . You'd use Assembly.GetExecutingAssembly().GetManifestResourceStream to load it.
Unfortunately, SqlXmlCommand only accepts paths to the SchemaPath So, you embed the XSD, then write it out as a temporary file, use it, and delete the temporary file:
string tmpFilePath = Path.GetTempFileName();
try
{
TextReader rdr = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("MyDataAccess.MySchemaFile.xsd");
TextWriter wr = new StreamWriter(tmpFilePath, false);
wr.WriteLine(rdr.ReadToEnd());
wr.Close();
rdr.Close();
}
catch (Exception e)
{
}
finally
{
if (File.Exists(tmpFilePath)) File.Delete(tmpFilePath);
}
|
|
|
|
|
i am currently trying to create a combo box which will then display "yes" and "no" when i run the macro, the combo box is created in visual basic!
any feed back would be appreciated!
sincerely
hyper Robster
|
|
|
|
|
I'm trying to develop a web based C# app that will read in any xml document and then display the information in a tree form. The user can then expand the parent nodes through a drilldown list and edit its children. Anyone know how I can go about doing this? I've only been able to get the app to update/add/and edit but I don't know how to display the hierarchy. Any help is appreciated.
|
|
|
|
|
How do I put a string into a xml file in a windows application, in a window form? I use a DataReader for accessing data from my database(and not a dataset).
When I was working to a project in ASP, I used
xmlfile.DocumentContent=mystring;
but in windows forms the xml document doesn't have "DocumentContent" property!
|
|
|
|
|
Well yeah, you just can't arbitrarily stick a string into the middle of XmlDocument . Can you elaborate on what you are trying to accomplish? You are iterating over a DataReader for data to do what with it? If you want to insert a new XmlNode into the XmlDocument there are plenty of examples of how that works around.
|
|
|
|
|
Why not use a dataset? Then you could retrieve the xml using the getxml and insert your nodes as required.
|
|
|
|