|
Hi
Struggling here to sort, using xpath, an xml file by absolute numerics. My data (unfortunately) comes in comma formatted :-
<line id="1" impact="100,000,000.00"><br />
<line id="2" impact="-110,000,000.56">
I need to display this in order of the absolute value. I have googled and found the following xpath expression, but it doesn't seem to work. Any ideas?
expr.AddSort("concat( substring('-', 2 - (@impact < 0)), '1' ) * @impact", ( System.Xml.XPath.XmlSortOrder.Ascending , System.Xml.XPath.XmlCaseOrder.None, "", System.Xml.XPath.XmlDataType.Number);
Cheers
|
|
|
|
|
Sorted! (pardon the pun)
<br />
class myComparer : IComparer<br />
{<br />
<br />
public int Compare(object x, object y)<br />
{<br />
double l1 = double.Parse(x as string);
double l2 = double.Parse(y as string);<br />
l1 = Math.Abs(l1);<br />
l2 = Math.Abs(l2);<br />
<br />
if (l1 < l2) return -1;<br />
<br />
if (l1 > l2) return 1;<br />
<br />
return 0;<br />
}<br />
}<br />
and then use the comparer in the xpath expression
<br />
expr.AddSort("@Value" , new myComparer())<br />
Happy to be told there is a better way...
Cheers
|
|
|
|
|
My exercise is using Eclipse to write a web application, and requirement is using XML to write database. Please show me how, thanks so much! : )
|
|
|
|
|
|
hihi i'm a newbe in Java. If u don't mind, please show me basic code to create an XML file (i understood XML structure), how to retrieve data from this file and write data to it. I need to develop my application in "Eclipse.exe".
Follow your instruction i read on "http://developerlife.com/xmljavatutorial1/default.htm" and see this coding:
import com.sun.xml.tree.*;<br />
import org.w3c.dom.*;
You must have the a String URL of the XML document before you can instantiate a DOM object from it. Assume that an XML file called AddressBook.xml is at the following URL:
http://beanfactory.com/xml/AddressBook.xml. Here is the code to create a DOM object from this URL:
try <br />
{ <br />
String url = "http://beanfactory.com/xml/AddressBook.xml"; <br />
Document doc = XmlDocumentBuilder.createXmlDocument(url);<br />
}<br />
catch(Exception e){}
But i can not download Sun's parser or IBM's parser.
Can u tell me another way : )
-- modified at 1:55 Tuesday 19th December, 2006
|
|
|
|
|
These parsers might be available to you:
http://xerces.apache.org/[^]
or
http://www.jclark.com/xml/[^]
Also, I am really a C++ programmer with a little Java programming knowledge. So, I cannot really give a good example using Eclipse.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
hihi me too. I use C as my main language, but my new project using Java and Japanese. So i must try so much Arigato
|
|
|
|
|
Hi,
Can anyone plz tell me how to use XMl SChema.Me a Beginner in Xml ..
the exact requirment is ....
I have to store the textbox values from ASP.NET in to a XML file using XML schema.
hope u guys vl help me to solve this..
Thanks in advance..
Regards
Bino Varghese
|
|
|
|
|
Simply spoken a XML Schema describes a set of elements and attributes and how these are allowed to be nested. Each XML file that claims to conform to the Schema has to follow these rules.
In your case the Schema has nothing to do with the storing process itself, but it gives you the possibility to validate whether your storage file (still) has the expected structure/content.
Out there are many tutorials on XML and XML Schema that can be easily found with google or the search engine of your choice. I suggest you read some of them, try to solve the problem on your own and come back if you get stuck at some point.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thank u Stefan 4 ur reply.
U have cleared my doubt.I take ur suggestions to start reading abt XML Schema.
Can u please suggest me some tips how to store values from a Texbox of ASP.NET page to XML .
me using SQL2005 to store values but the client wants it to be XML FILE.
so plz help me dude.
Thanking you
Bino Varghese
|
|
|
|
|
Well your best bet would be to use an instance of XmlDocument class that gives you a DOM representation of your XML file and add nodes to it according to the structure of your XML. Take a look at the MSDN documentation for the XmlDocument class which provides some examples and many links for further reading.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thank you Stefan
|
|
|
|
|
how to read the content of the XML File when we dont know the nodes.
Mohinder Singh
|
|
|
|
|
If you're using DOM to access the XML file you can simply iterate over the child nodes of a given node starting with the document's root node.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi all,
i am new to .net technology (and also to XML). please can anyone explain me these:
1.When we are constructing an XML DTD, how can we create an external entity reference in an attribute value?
2.please can u Give some examples of XML DTDs or schemas that we generally have to work with?
3.which type of applications that can benefit from using XML?
Thanks,
Rahi
If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
Rahithi wrote: 3.which type of applications that can benefit from using XML?
XML is *great* for configuration files, and, of course, for data exchange between different applications. About every configurable application that exports or imports data will benefit from XML.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
Thanks for ur response. can u answer my first 2 questions please.......
If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
Is the following what you are looking for?
File hello.ent contents:
<?xml encoding="UTF-8"?>Hello
File entity.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE greetings [
<!ENTITY greet SYSTEM "hello.ent">
]>
<root>
<say word="&greet;"/>
</root>
As for other questions see:
http://www.w3schools.com/dtd/default.asp[^]
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-- modified at 2:51 Saturday 16th December, 2006
|
|
|
|
|
I have this schema as shown below. I need to generate an xml file that will use the schema. Note the nested nature of the schema. What i got gave error validated by client. I am in deep sh*t now need help get this working. i work with vb.net or c#
the schema
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="PENCOM_REPORT"
targetNamespace="http://tempuri.org/QCR101.xsd"
xmlns="http://tempuri.org/QCR101.xsd"
xmlns:mstns="http://tempuri.org/QCR101.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified"
elementFormDefault="qualified">
<xs:element name="QCR101" msdata:IsDataSet="true" msdata:EnforceConstraints="False">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="REPORT_HEADER">
<xs:complexType>
<xs:sequence>
<xs:element name="REPORT_CODE" type="xs:string" minOccurs="0" />
<xs:element name="REPORT_NAME" type="xs:string" minOccurs="0" />
<xs:element name="PFA_CODE" type="xs:string" minOccurs="0" />
<xs:element name="PFA_NAME" type="xs:string" minOccurs="0" />
<xs:element name="REPORT_DATE" type="xs:string" minOccurs="0" />
<xs:element name="TOTAL_AMOUNT" type="xs:string" minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="REPORT_DATA">
<xs:complexType>
<xs:sequence>
<xs:element name="ITEMS_DATA" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="SERIAL_NO" type="xs:string" minOccurs="0" />
<xs:element name="DESCRIPTION" type="xs:string" minOccurs="0" />
<xs:element name="AMOUNT" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="REPORT_FOOTER">
<xs:complexType>
<xs:sequence>
<xs:element name="CONTACT_DETAILS" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="NAME" type="xs:string" minOccurs="0" />
<xs:element name="TEL_NO" type="xs:string" minOccurs="0" />
<xs:element name="EXTN" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
tanks in advance
-- modified at 11:01 Wednesday 13th December, 2006
|
|
|
|
|
Either enable the "Ignore HTML tags in this message" checkbox beneath the smilies or replace all < with <, cause otherwise we see neither your schema nor the xml fragment.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Ok there is the schema, but I don't see your XML file that happens to fail validation.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hey guys, i'm fearly new to xml (espacially xpath) and need a little help here..
My XML document looks like
<br />
<?xml version="1.0" encoding="ISO-8859-1" ?><br />
< Properties><br />
< Property><br />
<Number>10</Number><br />
<Type>Type A</TypeNL><br />
<Description>A nice description</Description><br />
</Property><br />
</Properties><br />
(added spaces in front of the Properties and Property element, because else they appear as smiley)
I'm trying to loop through all properties (ofcourse in my xml document there are more than one properties) and would like to retrieve the number, type and description of the property. I'm writing my app in C#
<br />
XPathDocument docRegion = new XPathDocument(_XmlFilePath);<br />
XPathNavigator navRegions = docRegion.CreateNavigator();<br />
XPathNodeIterator nodeProperty = navRegions.SelectChildren("//Properties/Property", "");<br />
I would expect the SelectChildren function to return a collection of all properties in my XML document, but i'm not getting the expected values returned. Am I doing something wrong, do I need a diffrent approach or something??
|
|
|
|
|
Eduard Keilholz wrote: (added spaces in front of the Properties and Property element, because else they appear as smiley)
You can enable the "Ignore HTML tags in this message" checkbox beneath the smilies to easily post XML fragments. Unfortunately this also disables the other formatting possibilities, but most times it's far more practically than inserting spaces or replacing < with <.
Eduard Keilholz wrote: Am I doing something wrong, do I need a diffrent approach or something??
Documentation says that SelectChildren selects only directly nested children and the first parameter should be a local name and no XPath expression. So either change the first parameter to "Property" (not sure if this works cause I'm not sure whether "Properties" is the current node of the the XPathNavigator ) or use the Select method which allows the use of XPath expressions.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Seems to be working pretty sweet, thnx a lot!
Stefan Troschütz wrote :
You can enable the "Ignore HTML tags in this message" checkbox beneath the smilies to easily post XML fragments. Unfortunately this also disables the other formatting possibilities, but most times it's far more practically than inserting spaces or replacing < with <.
I thought this would filter all html tags which disables me to insert xml
|
|
|
|
|
I never thought about it, but the checkbox label could be misinterpreted the way you did. Maybe "Treat HTML tags and there content as plain text" would be more precise.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|