|
Post some code to show what you are doing.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I have an application that displays a treeview with the following structure:
+ TreeRoot
+-+ Heading
| +-+ DataElement
| +-+ DataElement
| +-+ Heading
| +-+ DataElement
| +-+ DataElement
+-+ Heading
| +-+ DataElement
. . .
Note the data order is important and must be preserved.
I have stored this in a XML file like this.
<root>
<heading>
<dataelement>First data<\ DataElement>
<dataelement>Second data<\ DateElement>
<heading>
<dataelement>First nested data<\ DataElement>
<dataelement>Second nested data<\ DataElement>
<\ heading>
<\heading>
<heading>
<dataelement>data<\DataElement>
<\heading>
. . .
<\root>
I am able to read and writhe this data to and from the tree and update the xml file.
However I am not able to describe this structure in a Schema.
Is there a method that would be univerally portable to keep this structure.
I would prefer not to use H1, H2, H3 . . . method for the nested headers.
Thanks for the help.
|
|
|
|
|
let say I have this:
<books>
<book>
<title genre="non-fiction">Objects First With Java- A Practical Introduction Using Bluej </title>
<author>David J. Barnes</author>
<author>Michael Kolling</author>
<publisher>Pearson Prentice Hall</publisher>
<year>2006</year>
<price>49</price>
</book>
<book>
<title genre="fiction">Harry Potter and the Half-Blood Prince</title>
<author>J. K. Rowling</author>
<publisher>Thorndike Press</publisher>
<year>2005</year>
<price>29</price>
</book>
</books>
and I want to sum the price if the title genre is fiction and book price is less than 30 (I should have more books for this but will add later).
currently I read somewhere I came up with this:
<xsl:value-of select="sum(/books/book/title[@genre='fiction']/price[number(text())<30])" />
or this:
<xsl:value-of select="sum(/books/book[title[@genre='fiction']]/price[number(text())<30])" />
but it seems I still cant get it right. Anyone could help where I did wrong?
Edited:
I found the problem that I should use '& lt;30' instead of <30. I believe I did use lt before asking.
Anyway, why the< b r / > in my xsl file does not work in FireFox but it is fine with IE?
Many thanks.
modified on Friday, April 17, 2009 8:28 AM
|
|
|
|
|
You were almost there with your second effort:
sum(/books/book[title[@genre = 'fiction']]/price[. < 30])
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Using dot .& lt;30 seems to be working too and less confusing instead of number(text()).
Thanks for your reply.
|
|
|
|
|
Hello,
I'd like to make a project that has DOM support. I'm thinking of using Xerces. What I'd like too is to have a API to access the same DOM implementation both in C++ and JAVA..... I mean, some apps will use it through C++, others in Java, while the rest of the library will be C++. Is Xerces a good solution for that? As I see there are both Java and C++ bindings, will this help achieve what I need?
|
|
|
|
|
AFAIK the two Xerces (C++/Java) implementations are completely separate. It sounds like you have read something that says they are one implementation, could you supply a link to that?
gotchagotcha wrote: What I'd like too is to have a API to access the same DOM implementation both in C++ and JAVA
Why? The whole point is that the DOM is the standard and therefore the API's are mostly identical. Designing your applications with a DAL probably provides a much larger benefit than sharing a DOM implementation.
Also to use native code from Java requires the use of JNI so you can't directly utilize a C++ anything by writing pure Java code. Anyway if you are bent on doing this I suppose you could provide the JNI wrappers for the C++ Xerces DOM. It seems pointless to me but whatever.
|
|
|
|
|
Hi All,
I am writing the following code
"<a href="{@FileRef}" > <xsl:value-of select="@Title" />
</a>"
The problem is that my "FileRef" contains special character in it (like test's.aspx, the single quotes in it).In the browser the URL is shown as
test's.aspx.
Is there any work around for this.
I don't know how to handle the unsafe character in xslt.
Thanks in Advance
Alok....
modified on Wednesday, April 15, 2009 10:39 AM
<div class="ForumMod">modified on Wednesday, April 15, 2009 10:43 AM</div>
|
|
|
|
|
IMHO, I would avoid using "special" characters and white space in a URL since it always gets URL-encoded. In your case, the single quote will be change to %28 . Besides, since XSLT is really XML, you can use " instead of ' . Please note that you can place characters such as a single quote in CDATA sections!
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
please help me....
how can i convert data set to xml according to my DTD
R RajaGuru
|
|
|
|
|
Do you know what a DTD is, and why do you need to use one? If you have the answers to these questions, you should know what to do.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
|
hi all
This is to read the tag line by line.
using System.Xml;
...
...
...
XmlTextReader reader = new XmlTextReader ("reader.xml");
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
Console.Write("<" + reader.Name);
Console.WriteLine(">");
break;
case XmlNodeType.Text: //Display the text in each element.
Console.WriteLine (reader.Value);
break;
case XmlNodeType.EndElement: //Display the end of the element.
Console.Write("</" + reader.Name);
Console.WriteLine(">");
break;
}
}
Console.ReadLine();
How do i read the specific tag
if i just want to read all the tag that have this < big > tag?
thank you
|
|
|
|
|
This might help you get started:
reader.ReadToFollowing("big");
do
{
} while (reader.ReadToNextSibling("big"));
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
You can use XPath to simplify your work. For example:
XmlDataDocument xmlDoc = new XmlDataDocument();
xmlDoc.Load("yourfile.xml");
XmlNodeList xmlNodeList = xmlDoc.SelectNodes("roottag/big"); //XPath expression
More detail information pls. refer to Microsoft MSDN.
|
|
|
|
|
Unfortunately, our poster is using XmlTextReader . You don't use XPath with that.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hi all,
Can you please let me know how to change the following XML so that i have HOME and SERVICES as parent node.At the moment HOME Contains SERVICES as a Sub Node.
What i want is When i click on Home the Service Link shouldnt be hidden.
<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
<siteMapNode title="Home" >
<siteMapNode title="Services" >
<siteMapNode title="Training" url="~/Training.aspx"/>
</siteMapNode>
</siteMapNode>
</siteMap>
Thank you In advance.
|
|
|
|
|
kibromg wrote: What i want is When i click on Home the Service Link shouldnt be hidden.
I don't know if anyone will understand your post, I know I don't. XML is text so when you click on it nothing is going to happen.
My guess is you left some stuff out of your post under the mistaken notion that we already know what you are thinking and doing, we don't, that's not really how internet forums work. Or perhaps you don't know anything about XML yourself. If that is the case try some of the tutorials at www.w3schools.com
|
|
|
|
|
I'm using an XMLDataSource to pull rss feeds into my site. Some of the feeds have really long descriptions, so I'd like to limit the length of the description fields, and then append a "..." to the end.
Is there any way to do that?
|
|
|
|
|
Found solution. Here's ASP.net code in case it helps anyone else:
<pre> <asp:DataList ID="DataList1" runat="server" DataSourceID="XmlDataSource1" BackColor="#333333"
BorderStyle="None" GridLines="Vertical" BorderColor="#333333" BorderWidth="0px">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#XPath("pubDate")%>' Font-Names="Verdana" Font-Size="XX-Small"></asp:Label><br />
<asp:HyperLink ID="HyperLink1" runat="server" Text='<%#XPath("title")%>' NavigateUrl='<%#XPath("link")%>' Target="_blank" Font-Names="Verdana" Font-Size="Small"></asp:HyperLink><br />
<asp:Label ID="description_label" runat="server" Text='<%#XPath("description")%>'></asp:Label><br />
<br />
</ItemTemplate>
</asp:DataList>
Here's the code behind:
<pre> Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound
Dim ShortDescriptionLabel As Label = CType(e.Item.FindControl("description_label"), Label)
If ShortDescriptionLabel.Text.Length > 200 Then
ShortDescriptionLabel.Text = ShortDescriptionLabel.Text.Substring(0, 200) & "..."
End If
ShortDescriptionLabel.Text = ShortDescriptionLabel.Text
End Sub
|
|
|
|
|
hi im doing a small project for friend.. i need to get the data out of xml so that i can verify the username and password
xml is like this
PLEASE HELP THE ERROR I GET IS EXPLAINED IN THE MIDDLE.. THANKS ALOTTTT
<clientlogind>
<client username="faizych">
Password="pass"
/>
<client username="taha89">
Password="pass78"
/>
and to get the value im doing
private void button1_Click(object sender, EventArgs e)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load("path.xml");
System.Xml.XmlNodeList client;
XmlNode clientNode = xmldoc.DocumentElement;
client = clientNode.SelectNodes("Client");
string Usernamttext = txtUsername.Text;
string passwordtext = txtpassword.Text;
foreach (XmlNode DataNode in client)
{
string userid;
string password;
************************************************************************************************
******* ERROR HERE*** now when i run it it gives me an error when it gets to the line below that """object reference not set to an instance of an object"""
*************************************************************************************************
userid = DataNode.SelectSingleNode("Username").InnerText.Trim();
password = DataNode.SelectSingleNode("password").InnerText.Trim();
if (string.Compare(Usernamttext, userid) == 0)
{
if (string.Compare(passwordtext, password) == 0)
{
break;
UserProfile UserProfileForm = new UserProfile();
UserProfileForm.usernamevalue = userid;
UserProfileForm.Show();
this.Close();
}
else
{
MessageBox.Show("Invalid Username or password");
}
}
}
}
|
|
|
|
|
Your error has nothing to do with XML itself.
The call to DataNode.SelectSingleNode probably returns null. In fact, directly calling methods on method calls that are prone to return null is one of the worst coding habit someone can have.Here is what a good programmer would have done:
userid = DataNode.SelectSingleNode("Username");
if ((userid != null) && (!String.IsNullOrEmpty(userid.InnerText))
{
}
else
{
throw new NoUsernameNodeException();
}
Not checking for null values before using object references is one the worst thing to do, always leading to obscure error message "Object reference not set to an object".
|
|
|
|
|
I was hoping someone could give me a hand with this. I'd like to convert a standard XML file into one that groups the data by one of the data elements.
Here is a sample of data I'd be using:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Inventory>
<Item>
<producttype>Book</producttype>
<productname>A Connecticut Yankee in King Arthur's Court</productname>
<artistfirstname>Mark</artistfirstname>
<artistlastname>Twain</artistlastname>
<description>A Connecticut Yankee travels back to King Arthur's court and adventure ensues. Fun, fun, fun.</description>
<company>Pocket Books</company>
<year>1889</year>
<productid>978-1416534730</productid>
<price>4.95</price>
<image/>
</Item>
<Item>
<producttype>Book</producttype>
<productname>A Farewell To Arms</productname>
<artistfirstname>Ernest</artistfirstname>
<artistlastname>Hemingway</artistlastname>
<description>The tragic tale of love and loss during WWI.</description>
<company>Charles Scribner's Sons</company>
<year>1929</year>
<productid>978-0684837888</productid>
<price>18.15</price>
<image href="file://images/978-0684837888.jpg"/>
</Item>
<Item>
<producttype>Book</producttype>
<productname>A Portrait of the Artist as a Young Man</productname>
<artistfirstname>James</artistfirstname>
<artistlastname>Joyce</artistlastname>
<description>A a fictionalized memoir of Joyce's alter ego, Stephen Daedelus, describing his coming of age in Dublin.</description>
<company>Everyman's Library</company>
<year>1916</year>
<productid>978-0679405757</productid>
<price>14.25</price>
<image href="file://images/978-0679405757.jpg"/>
</Item>
<Item>
<producttype>Audiobook</producttype>
<productname>A Tale of Two Cities</productname>
<artistfirstname>Charles</artistfirstname>
<artistlastname>Dickens</artistlastname>
<description>Classic telling of life in two cities, London and Paris, during the upheaval of the French Revolution.</description>
<company>Blackstone Audiobooks</company>
<year>2005</year>
<productid>978-0786180394</productid>
<price>19.77</price>
<image href="file://images/978-0786180394.jpg"/>
</Item>
<Item>
<producttype>Audiobook</producttype>
<productname>Anna Karenina</productname>
<artistfirstname>Leo</artistfirstname>
<artistlastname>Tolstoy</artistlastname>
<description>Audiobook version of the intricate intrigue of love and scandal in high society of Czarist Russia.</description>
<company>Naxos Audiobooks</company>
<year>1999</year>
<productid>978-9626340813</productid>
<price>20.55</price>
<image href="file://images/978-9626340813.jpg"/>
</Item>
</Inventory>
I'd like to end up with something like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Inventory>
<category>
<type>Book</type>
<Item>
<productname>A Connecticut Yankee in King Arthur's Court</productname>
<artistfirstname>Mark</artistfirstname>
<artistlastname>Twain</artistlastname>
<description>A Connecticut Yankee travels back to King Arthur's court and adventure ensues. Fun, fun, fun.</description>
<company>Pocket Books</company>
<year>1889</year>
<productid>978-1416534730</productid>
<price>4.95</price>
<image/>
</Item>
<Item>
<productname>A Farewell To Arms</productname>
<artistfirstname>Ernest</artistfirstname>
<artistlastname>Hemingway</artistlastname>
<description>The tragic tale of love and loss during WWI.</description>
<company>Charles Scribner's Sons</company>
<year>1929</year>
<productid>978-0684837888</productid>
<price>18.15</price>
<image href="file://images/978-0684837888.jpg"/>
</Item>
<Item>
<productname>A Portrait of the Artist as a Young Man</productname>
<artistfirstname>James</artistfirstname>
<artistlastname>Joyce</artistlastname>
<description>A a fictionalized memoir of Joyce's alter ego, Stephen Daedelus, describing
his coming of age in Dublin.</description>
<company>Everyman's Library</company>
<year>1916</year>
<productid>978-0679405757</productid>
<price>14.25</price>
<image href="file://images/978-0679405757.jpg"/>
</Item>
</category>
<category>
<type>Audiobook</type>
<Item>
<productname>A Tale of Two Cities</productname>
<artistfirstname>Charles</artistfirstname>
<artistlastname>Dickens</artistlastname>
<description>Classic telling of life in two cities, London and Paris, during the
upheaval of the French Revolution.</description>
<company>Blackstone Audiobooks</company>
<year>2005</year>
<productid>978-0786180394</productid>
<price>19.77</price>
<image href="file://images/978-0786180394.jpg"/>
</Item>
<Item>
<productname>Anna Karenina</productname>
<artistfirstname>Leo</artistfirstname>
<artistlastname>Tolstoy</artistlastname>
<description>Audiobook version of the intricate intrigue of love and scandal in high
society of Czarist Russia.</description>
<company>Naxos Audiobooks</company>
<year>1999</year>
<productid>978-9626340813</productid>
<price>20.55</price>
<image href="file://images/978-9626340813.jpg"/>
</Item>
</category>
</Inventory>
Does anyone know how to write an XSLT to create this kind of grouping?
If you have any suggestions, I'd entertain any options.
Thanks
|
|
|
|
|
blindcapt wrote: Does anyone know how to write an XSLT to create this kind of grouping?
What kind of grouping? I'm not going to reverse engineer your XML to decipher the problem statement for you. If you understand your problem clearly, you should have no trouble stating it in a post.
|
|
|
|
|
Each record contains these elements: producttype, productname, productid, productprice
I want the elements to group under the producttype element, such as:
Original:
<products>
<item>
producttype
productname
productid
productprice
</item>
<item>
producttype
productname
productid
productprice
</item>
</products>
Desired:
<products>
<category>
<producttype></producttype>
<item>
productname
productid
productprice
</item>
<item>
productname
productid
productprice
</item>
</category>
<category>
<producttype></producttype>
<item>
productname
productid
productprice
</item>
<item>
productname
productid
productprice
</item>
</category>
</products>
|
|
|
|