|
I am working on a project for a State Agency where the data is received from multiple private entities and loaded into SQL 2005 tables. The XML schema was designed and published before my involvement with the project and now it cannot be changed. One of the elements to receive (Charges) occurs multiple times within a client but each is for a different concept. Instead of using an attribute to identify the reason for the Charge, they used the element name to do it. For example:
<FERTILIZER_CHARGE>2300</FERTILIZER_CHARGE> -- 20 different charge types identified
instead of
<CHARGE TYPE=”FERTILIZER” AMOUNT=”2300” />
I need to move all the charges to a single table and identify each one with its type but cannot find any examples where the element name is used to update a column in a table. PLEASE HELP!!!
|
|
|
|
|
i just want to load one image to the picturebox, who's path is stored in xml file. please tell me how to do this.
GIve examples.
|
|
|
|
|
kpuneeth7 wrote: GIve examples
Without knowing a little about the structure of your XML file and what technology you're using, that would be difficult to do...
But it's simply a case of reading the XML file with an XML parser (think XmlReader in .NET), and finding the node containing the image file's path.
The rest of it (displaying the image in the picture box) is nothing to do with XML.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
I am using a simple xml file.....
<path>C:\Documents and Settings\Imran\Desktop\Picture\apple.jpg
And i am using visual studio 2008
C# language.
.net frameworkmodified on Wednesday, February 24, 2010 3:20 AM
|
|
|
|
|
Here's a short C# program that will read the bit of XML you want and write it to the console.
using System.Xml.XPath;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string imagePath = new XPathDocument(new StreamReader(args[0])).CreateNavigator().SelectSingleNode("/image/img").Value;
System.Console.WriteLine(imagePath);
}
}
}
I've used XPath to navigate to the required element in the XML file (that's the .SelectSingleNode("/image/img") bit) and read the text there (the .Value bit). Simples.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
Thanks for the code....
BUt its giving indexoutofrange exception......
HElp
|
|
|
|
|
You need to give a command line argument that specifies the XML file...the code comments DO say that.... Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
Thanks dude.....
I got it
Thank u very much
|
|
|
|
|
I have the following input XML. I want to group all unique Code/ID combination.
<List>
<Section>
<Code>AA</Code>
<ID>11</ID>
<Section>
<Section>
<Code>AA</Code>
<ID>11</ID>
<Section>
<Section>
<Code>CC</Code>
<ID>11</ID>
<Section>
<Section>
<Code>AA</Code>
<ID>22</ID>
<Section>
<Section>
<Code>AA</Code>
<ID>11</ID>
<Section>
<List>
So result should be as shown below.
<Code>AA</Code>
<ID>11</ID>
<Code>CC</Code>
<ID>11</ID>
<Code>AA</Code>
<ID>22</ID>
Im using the Muenchian Method. Currely my XSL (below) is grouping by Code (and not Code/ID combination)
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var" version="1.0" xmlns:ns0="http://A4C.Interface.HRP.Payroll.Schemas">
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
<xsl:key name="CCids" match="/List/Section" use="Code"/>
<xsl:template match="/">
<xsl:apply-templates select="/ns0:Payroll" />
</xsl:template>
<xsl:template match="/ns0:Payroll">
<ns0:List>
<xsl:for-each select="/List/Section [generate-id(.)=generate-id(key('CCids',Code))]">
<Section>
<Code>
<xsl:value-of select="code/text()" />
</Code>
<ID>
<xsl:value-of select="id/text()" />
</ID>
</Section>
</xsl:for-each>
</ns0:List>
</xsl:template>
</xsl:stylesheet>
How do i get this to use a Code/ID combination? I tried nested for-each loop but no luck. Thanksmodified on Tuesday, February 23, 2010 11:40 AM
|
|
|
|
|
Firstly, your key needs to have an expression which reflects what you want to retrieve:
<xsl:key name="CCids" match="/List/Section" use="concat(Code,'|',ID)"/>
And then you need to use that same expression when accessing items referenced by the key.
Oh - and in addition, I would suggest not using a for loop - it's not idiomatic XSL. Here's the file I'd use:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var" version="1.0" xmlns:ns0="http://A4C.Interface.HRP.Payroll.Schemas">
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0" encoding="utf-8"/>
<xsl:key name="CCids" match="/List/Section" use="concat(Code,'|',ID)"/>
<xsl:template match="/">
<ns0:List>
<xsl:apply-templates select="/List/Section [generate-id(.)=generate-id(key('CCids',concat(Code,'|',ID)))]"/>
</ns0:List>
</xsl:template>
<xsl:template match="Section">
<Section>
<Code>
<xsl:value-of select="Code/text()" />
</Code>
<ID>
<xsl:value-of select="ID/text()" />
</ID>
</Section>
</xsl:template>
</xsl:stylesheet> Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
Thanks..Really helpful
|
|
|
|
|
Hi,
I am getting this error There is an error in XML document (1, 2)
When i Deserialize following Xml.
<EnvironmentConfigurations>
<EnvironmentConfiguration>
<EnvironmentName>ABC</EnvironmentName>
<CMSConfiguration>
<Address>net.tcp://localhost:9000/Manager</Address>
<Binding>netTcpBinding</Binding>
<Contract>Common.Interfaces.Server</Contract>
</CMSConfiguration>
</EnvironmentConfiguration>
<EnvironmentConfiguration>
<EnvironmentName>XYZ</EnvironmentName>
<CMSConfiguration>
<Address>net.tcp://localhost:9000/Manager</Address>
<Binding>netTcpBinding</Binding>
<Contract>Common.Interfaces.Server</Contract>
</CMSConfiguration>
</EnvironmentConfiguration>
</EnvironmentConfigurations>modified on Tuesday, February 23, 2010 5:11 AM
|
|
|
|
|
Deserialize to what? The way in which it's deserialized depends on the type you think it is.
Are you sure this was serialized from .NET? That's not the only way to read and write XML, you know - maybe you should be using an XMLReader and parsing the XML yourself?Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
I have serialized using XmlSerializer.
I have removed Xml version and namespace information from the XML.
I have changed the root node from
<ArrayOfEnvironmentConfigurations> to <EnvironmentConfigurations>
I want to desrialize this xml.
Thank you.
|
|
|
|
|
The answer to your problem is very, very clear - don't mess with the XML that the serializer produces - all of the things you changed are in there for a reason!!!! Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
The problem was with the root node element which i changed.
I kept the root name as ArrayOfEnvironmentConfigurations and the problem was solved.
Thanks for replying.
|
|
|
|
|
Hi everyone,
I came across this prob...
I am a beginner in xml.
I wanted to create a xml file which stores the location of the images.
This xml file must be accessed in visual studio picture box and it must display each image wen i click the next button and back wen i press the previous button...
Please help
|
|
|
|
|
kpuneeth7 wrote: I am a beginner in xml.
Then you should study some of the tutorials here and on MSDN on the use of XML. From the remainder of your question it appears that you are asking for a complete image viewer solution. If you have no idea how to start on this problem then you have a lot of studying still to complete.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="BookEasy">
<xsd:element name="BookEasy">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Control">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ControlID" type="xsd:int"/>
<xsd:element name="ReservationRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="InDate" type="xsd:dateTime"/>
<xsd:element name="Period" type="xsd:int"/>
<xsd:element name="Adults" type="xsd:int"/>
<xsd:element name="Children" type="xsd:int"/>
<xsd:element name="Infants" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Operators">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Operator" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="OperatorID" type="xsd:int"/>
<xsd:element name="Rooms">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Room" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="RoomID" type="xsd:int"/>
<xsd:element name="Availability">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="IsAvailable" type="xsd:boolean"/>
<xsd:element name="Days">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Day" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Date" type="xsd:dateTime"/>
<xsd:element name="IsAvailable" type="xsd:boolean"/>
<xsd:element name="Rates">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="FullRate" type="xsd:decimal"/>
<xsd:element name="LastMinuteRate" type="xsd:decimal"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>modified on Tuesday, February 23, 2010 12:29 AM
|
|
|
|
|
Do you have a question? I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi,
I want to delete the duplicate and some hard coded XML node in XMLDocument throgh C#.
What is the method to do the same?
I am new to the use of XML in C#.
Please help me out.....!!!!!!!!!!!
Thanks
|
|
|
|
|
Hi All,
I try to use MSXML with xml files which contains namespaces. But I can't figure out how to do!
Here is an excerpt of my XML file:
<?xml version="1.0" encoding="utf-8"?>
<BENCH xmlns:VODPC_VOD="urn:VODPC:VOD:schema:20060809">
<VODPC_VOD:GRAPH state="running" currentFlowID="1" removeOnExit="FALSE">
</VODPC_VOD:GRAPH>
</BENCH>
When I load the file with MSXML6, no problem.
I try to access node BENCH with XPath "/BENCH" : no problem.
But when I try to access node VODPC_VOD:GRAPH with XPath "/BENCH/VODPC_VOD:GRAPH", I get an exception, which contain no valuable information:
First-chance exception at 0x75ac9617 in XXXXXX.exe: 0xE0000001: 0xe0000001.
First-chance exception at 0x75ac9617 in XXXXXX.exe: 0xE0000001: 0xe0000001.
First-chance exception at 0x75ac9617 in XXXXXX.exe: 0xE0000001: 0xe0000001.
First-chance exception at 0x75ac9617 in XXXXXX.exe: 0xE0000001: 0xe0000001.
First-chance exception at 0x75ac9617 in XXXXXX.exe: Microsoft C++ exception: _com_error at memory location 0x0025dac4..
I set these flags before to load:
m_pXMLDoc->async = VARIANT_FALSE;
m_pXMLDoc->preserveWhiteSpace = VARIANT_TRUE;
m_pXMLDoc->validateOnParse = VARIANT_TRUE;
m_pXMLDoc->resolveExternals = VARIANT_TRUE;
As you can understand, I work in C++. I'm an IT profesionnal since 18 year.
My problem is that I do not know what namespace is used in the file, so I don't want to have to tell MSXML6 what namespaces are used IN THE FILE. I guess it's its job, no ?
If anybody have an idea ...
Thanks a lot
Patrice
|
|
|
|
|
You have to tell MSXML what namespace prefixes your XPath expressions use. When parsing XML, the parser remmebers the namespace URIs, NOT the prefixes used in the documents. That means that your code has to define the prefix to URI mappings used in your XPaths. Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
Hi all,
I've xml string and I can load it with XmlDataDocument.LoadXml successfully,
so that OuterXml shows the real xml string. But when I want to load in a dataset, the result dataset has no table(Tables.Count=0).
Typical code is as follows:
...
XmlDataDocument Doc = new XmlDataDocument();
/*
string Str = "<Result><DN>22800661</DN><ID>1</ID><Status><Line>Idle</Line></Status></Result>";
*/
Doc.LoadXml(Str);
DataSet datasetResult = Doc.DataSet;
if(datasetResult.Tables.Count == 0) return;
...
and it returns that means datasetResult.Tables.Count is always 0.
Can anyone help me, what is wrong?
Thanks in advance
|
|
|
|
|
Maybe this is what you want ?
string Str = "<Result><DN>22800661</DN><ID>1</ID><Status><Line>Idle</Line></Status></Result>";
System.IO.StringReader sr = new System.IO.StringReader(Str);
XmlDataDocument Doc = new XmlDataDocument();
Doc.DataSet.ReadXml(sr);
DataSet datasetResult = Doc.DataSet;
if (datasetResult.Tables.Count == 0) return;
|
|
|
|