|
can anybody help? I don't know how to do that!
|
|
|
|
|
Hi,
I have the following code:
public class Item
{
private string name;
private int id;
[XmlElementAttribute]
public string Name
{
get{return name;}
set{name=value;}
}
[XmlElementAttribute]
public int ID
{
get{return id;}
set{id=value;}
}
}
I need to serialize an ArrayList of these Item(s).
public class Dummy
{
[XmlElementAttribute(typeof(Item))]
private ArrayList list;
public Dummy()
{
list=new ArrayList();
list.Add(new Item("one",1));
list.Add(new Item("two",2));
}
//this is called by a class that instantiates Dummy
public void save()
{
XmlSerializer ser=new XmlSerializer(typeof(Item));
StreamWriter writer=new StreamWriter("file.xml");
ser.Serialize(writer,list);
writer.Close();
}
}
but this won't work. Can anyone offer any suggestions?
thanx
|
|
|
|
|
Either make the list field public or make a read/write property for it. Xml serialization will not work on private fields. The reason for this is that the XmlSerializer builds some dynamic types to perform serialization instead of doing it by reflection. This puts the serialization outside of your namespace and it only has access to what is public. Which is also why you need a public default constructor. You also need to use the XmlArrayAttribute:
[XmlArray]
[XmlArrayItem(typeof(Item))]
public ArrayList list;
Logifusion[ ^]
If not entertaining, write your Congressman.
|
|
|
|
|
Hi everyone,
I want to using xmldom but i dont have microsoft.xmldom in my computer can you give me a site that i can download it.
Thanks
|
|
|
|
|
|
Thanks mike but which?theres many title?
|
|
|
|
|
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...
|
|
|
|