|
I need to store some Key/Value pairs associated with a value(id) in a XML file.The xml file would have the following structure :
<language id=1>
<key1>value</key1>
<key2>value</key2>
<key3>value</key3>
.
.
.
</language>
<language id=2>
<key1>value</key1>
<key2>value</key2>
<key3>value</key3>
.
.
.
</language>
.
.
.
My question is How I can save and retrieve information to and from the document.Show me the full code please.
Because I may have more than one xml file of this type that each store different key/value pairs,I need a class that encapsulate everything.I mean it takes as an argument the file name and language "id" and then retrieve all key/value pairs associated with that "id" and we can access them using the class properties.Show me the attributes,methods... the class should have,the data types the class should use.(e.g. IEnumerable ...)
I need to use this in a multi-language website for storing static contents for different languages. I need it soon. Help me please !
Thanks
-- modified at 10:18 Friday 8th September, 2006
|
|
|
|
|
Deserializing into a dictionary is not an automatic thing, so you'd have to do this custom. Nobody's going to give you the "full code" for it though. You have to try writing it yourself and post something when you get stuck. But, after reading this statement:
devboycpp wrote: I need to use this in a multi-language website for storing static contents for different languages.
I'm curious why you're doing this in XML. The internationalization capabilities in .NET are very good. You can create a resx file that works in the same way for this key/value pair idea. It can localize strings based on language and region and it uses the current regional settings from the user. Using the built-in stuff, you can automatically adjust date/time, currency, and number formats to match the current region. There are all kinds of articles on CP and elsewhere describing how to do this.
Logifusion[ ^]
If not entertaining, write your Congressman.
|
|
|
|
|
Does internationalization capabilities in .NET let the user add new languages ?
My site is going to let site adminitrators add new languages(unlimited).Does the .NET built-in feature let me do this ?
|
|
|
|
|
Have a look at this article to get a pretty good description of how to do globalization: http://www.codeproject.com/useritems/localization.asp[^]
Adding new languages is as simple as editing the resx file. There are global and local resx files as well. Meaning you can have one resx file per aspx or ascx. You can also have a resx for the whole application for common strings. If you want to allow an administrator to change resx files through the web application, I suppose the best way would be to use the System.Resources.ResXResourceWriter .
Logifusion[ ^]
If not entertaining, write your Congressman.
|
|
|
|
|
devboycpp wrote: Show me the full code please.
Well asking people to do your work for you does not generaly produce a good response on Code Project.
devboycpp wrote: How I can save and retrieve information to and from the document.
Also I would use an XML structure that does not use different element names for each entry.
That depends on the development environment/language you are working with. For .NET there is the System.Xml namespace that contains many different ways to work with XML (the most obvious is System.Xml.XmlDocument). For VC++ Native applications and I guess even VB you can use the MSXML ActiveX control and COM interfaces. For all of those things I am sure there is an abundance of help-samples-examples here on Code Project and MSDN.
<language id="2">
<entry name="key1" value="whatever"/>
<entry name="key2" value="something"/>
<\language>
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real" Score: 1.0 in the Soap Box
led mike
|
|
|
|
|
What do you mean when you say this? :
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real"
Of course internet exists and is real .
|
|
|
|
|
It is a quote from a user named "Score: 1.0". Something he said in the Soapbox forum.
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real" Score: 1.0 in the Soap Box
led mike
|
|
|
|
|
I use .NET. I already know XML namespace I just want to know details.
|
|
|
|
|
devboycpp wrote: I already know XML namespace I just want to know details.
The hide those details along with example code snippets in the Documentation[^]
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real" Score: 1.0 in the Soap Box
led mike
|
|
|
|
|
I'd suggest using an XML serializable model. You can use it to read and write the file using XmlSerilaizer and just deal with the model, not the XML.
using System;
using System.Xml.Serialization;
namespace XmlEntities {
[XmlRoot("File")]
public class File {
private Language[] element_language;
[XmlElement("language")]
public Language[] Languages {
get { return element_language; }
set { element_language = value; }
}
}
public class Language {
private System.Int32 attribute_id;
private Entry[] element_entry;
[XmlAttribute("id")]
public System.Int32 Id {
get { return attribute_id; }
set { attribute_id = value; }
}
[XmlElement("entry")]
public Entry[] Entries {
get { return element_entry; }
set { element_entry = value; }
}
}
public class Entry {
private System.String attribute_name;
private System.String attribute_value;
[XmlAttribute("name")]
public System.String Name {
get { return attribute_name; }
set { attribute_name = value; }
}
[XmlAttribute("value")]
public System.String Value {
get { return attribute_value; }
set { attribute_value = value; }
}
}
}
Generated from an XML sample with Skeleton Crew 2.0[^] But you can use xsd.exe if you don't mind slop code.
|
|
|
|
|
Hello There
There are two commands in XSL but both are generating Unknown Error (No output) i-e <xsl:import href="C:\External.xsl"> or <xsl:include href="C:\External.xsl">
Can any one guide me how to use External XSL into any other XSL ?
Also if I need to use Some parameters Like Path Of XML File to External.xsl file then what to do ?
|
|
|
|
|
I'm a little unsure about your question. To import another XSL into yours you do something like this:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="Generic.xsl"/>
<xsl:output method="xml"/>
I put the import in right after the stylesheet node. Then you can use any of the templates from the Generic.xsl sheet.
Logifusion[ ^]
If not entertaining, write your Congressman.
|
|
|
|
|
<xsl:stylesheet extension-element-prefixes="java" xmlns:java="http://xml.apache.org/xslt/java"
version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="foobar" select="foobar"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="add[@key=Web.Server]">
<xsl:copy>
<xsl:attribute name="key">
<xsl:value-of select="@key"/>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:text>hello world</xsl:text>
</xsl:attribute>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
I am trying to copy the entire web.config file and just change one value attribute to a particular entry. Here copy all, except if the key = web.Server
Please help
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
-- modified at 9:51 Friday 8th September, 2006
|
|
|
|
|
Hi,
I need to parse the following XML file for the nodes that have parent=1
<folders>
<folder>
<id>1</id>
<name>name1</name>
<parent>0</parent>
</folder>
<folder>
<id>2</id>
<name>name2</name>
<parent>1</parent>
</folder>
<folder>
<id>3</id>
<name>name3</name>
<parent>1</parent>
</folder>
</folders>
I tried to do it like this, but nodes has just 1 item instead of 2.
string query = "/folders/folder[parent='1']";
XPathDocument document = new XPathDocument("folders.xml");
XPathNavigator navigator = document.CreateNavigator();
XPathNodeIterator nodes=navigator.Select(query);
Is there a way to do this?
thanx
|
|
|
|
|
There is nothing wrong with your query.
using namespace System;
using namespace System::Xml;
using namespace System::Xml::XPath;
int main(array<System::String ^> ^args)
{
String^ search = L"/folders/folder[parent='1']/id";
XPathDocument^ document = gcnew XPathDocument(".\\folders.xml");
XPathNavigator^ navigator = document->CreateNavigator();
XPathNodeIterator^ nodes = navigator->Select(search);
while(nodes->MoveNext()) {
Console::WriteLine(nodes->Current->Value);
}
return 0;
}
|
|
|
|
|
|
i have this
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
I am trying to copy the xml document line for line.
But it doesnt show the elements. Just the text within them.
I want an exact copy of the file.
Can someone please help
Nick
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real" Score: 1.0 in the Soap Box
led mike
|
|
|
|
|
I would like to learn about how to load attributes from a tag from a *.xml to a dropdownlist in HTML file. When I choose an item in this list, the page will sort and show only items in the xml file that related to that attribute.
Can any body help?
Thanks a lot
-------*------
Learn every day...
|
|
|
|
|
What version of MSXML can be used in Windows NT.
I am using this code for XP, using MSXML2.dll it working
<br />
TESTHR(CoInitialize(NULL)); <br />
TESTHR(docPtr.CreateInstance(TEXT("Msxml2.DOMDocument.3.0")));<br />
<br />
_variant_t varXml((_bstr_t)p_xmlFileName.c_str());<br />
_variant_t varOut((bool)TRUE);
But in NT this is not working. What shall I do?
What "Msxml2.DOMDocument.3.0" should it be?
Pradosh
|
|
|
|
|
Pradosh Tapan Datta wrote: What version of MSXML can be used in Windows NT.
What version[^] is installed?
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real" Score: 1.0 in the Soap Box
led mike
|
|
|
|
|
Hi all.
Some time before i pass to use VS 2005.But there is one problem.When i edit an xsd file, intelliscensy work not how in VS 7. So three elements appear every time when i begin typed new element (
|
|
|
|
|
Hi,
I have a problem getting the first and second node from a specific xmlnodelist, and display it.
Basically my xml file looks like this
<br />
'Tag means that there is an xml tag<br />
Tag CompanyList:<br />
Tag PrincipalDetail:<br />
Tag Name: John<br />
Tag Surname: Doe<br />
Tag Telephone: 0000<br />
Tag AddressLine: streets<br />
<br />
<br />
Here is my asp.net code<br />
<br />
<code><br />
Dim xmlDoc As XmlDocument = New XmlDocument<br />
xmlDoc.Load("c:\Company.xml")<br />
<br />
'Dim elem As XmlNode = xmlDoc.DocumentElement("PrincipalDetail")<br />
Dim elemList As XmlNodeList = xmlDoc.SelectNodes("/CompanyList/PrincipalDetail")<br />
Dim elem As XmlNode<br />
<br />
Dim nodeLength As Integer = elemList.Count<br />
Dim i As Integer<br />
Dim isValid As Boolean = False<br />
<br />
For i = 0 To nodeLength - 1<br />
If elemList.Count > 0 Then<br />
strInsertXMLToTXT += elemList(0).InnerText<br />
strInsertXMLToTXT += elemList(1).InnerText<br />
strInsertXMLToTXT += elemList(2).InnerText<br />
End If<br />
Next<br />
<br />
What am I doing wrong?
|
|
|
|
|
Hi,
Doing some xml/excel related work at present.
When I try to save my .xls file as .xml (i.e. save as .xml data format), an error message tells me that Excel cannot save the workbook because it does not contain any XML mappings.
This does not occur on other machines.
Any thoughts please?
|
|
|
|
|
Excel cannot save your workbook in the XML Data if you have not created one or more mapped ranges (mapped range: A range in an XML list that has been linked to an element in an XML map.).
If you have added an XML map to your workbook, follow these steps to map XML elements to your worksheet:
On the Data menu, point to XML, and then click XML Source to open the XML Source task pane.
To map one or more elements to your worksheet, select the elements in the XML Source task pane. To select nonadjacent elements, click one element, and then hold down CTRL and click each element.
Drag the selected elements to the worksheet location where you want them to appear.
If you haven't yet added an XML map to your workbook, or if your data is not contained within an XML list, you can instead save your workbook in the XML Spreadsheet file format.
Regards,
Bhupesh.
|
|
|
|