|
Hi,
I want to create a XSD schema to use for validating XML files like the following:
top>
top>
top>
top>
/top>
link> link> mid>
mid>
/top>
top>
bottom>
/top>
/top>
A "top" element can contain any number of "top" elements or any number of "link" elements or any number of "mid" elements. A "top" element can contain only one "bottom" element and no other element if it contains a "bottom" element. A "link" or "mid" or "bottom" element cannot contain any elements.
Any advice, please help?
-- modified at 2:51 Wednesday 2nd May, 2007
|
|
|
|
|
Not tested, but should be at least a good starting point:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="link">
<xs:complexType></xs:complexType>
</xs:element>
<xs:element name="mid">
<xs:complexType></xs:complexType>
</xs:element>
<xs:element name="bottom">
<xs:complexType></xs:complexType>
</xs:element>
<xs:element name="top">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:element ref="mstns:bottom"></xs:element>
</xs:sequence>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="mstns:top"></xs:element>
<xs:element ref="mstns:link"></xs:element>
<xs:element ref="mstns:mid"></xs:element>
</xs:choice>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sche
"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
|
|
|
|
|
Or even simpler...
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:complexType name="top">
<xs:sequence>
<xs:element name="top" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="link" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="mid" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="bottom" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:element name="top" type="top" />
</xs:schema>
|
|
|
|
|
This doesn't cover the requirements that a "top" element can contain only one "bottom" element and no other element if it contains a "bottom" element.
"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
|
|
|
|
|
True, didn't realize that was a requirement. I guess choice is the only valid approach.
|
|
|
|
|
i need to add node values in a xml file like
<country>
<india>
<states>1</states>
<states>2</states>
</india>
<America>
<value>xxx</value>
<value>xxx</value>
<value>xxx</value>
</America>
<Canada>
i need to add an xml node from other xml file ....
</Canada>
</country>
i need to add xmlnode value in Canada. it can be a nested node values
and the source for canada is from other xmlfile
i tryed with ImportRow method, but it appends in Root, (ie from <country>
i want to append data to <canada>
.....</canada>
Pls suggest
|
|
|
|
|
ImportRow is a DataTable method. If you are talking about XmlDocument, you can use the ImportNode method:
using namespace System;
using namespace System::Xml;
int main(array<System::String ^> ^args)
{
String^ srcXml =
L"<country>"
L"<canada>"
L"<lakes>yyyy</lakes>"
L"</canada>"
L"</country>";
XmlDocument^ srcDoc = gcnew XmlDocument();
srcDoc->LoadXml(srcXml);
XmlNode^ srcNode = srcDoc->SelectSingleNode(
L"/country/canada/lakes");
if (srcNode == nullptr)
{
Console::WriteLine(L"'lakes' node not found!");
return -1;
}
String^ destXml =
L"<country>"
L"<india>"
L"<states>1</states>"
L"<states>2</states>"
L"</india>"
L"<america>"
L"<value>xxx</value>"
L"<value>xxx</value>"
L"<value>xxx</value>"
L"</america>"
L"<canada/>"
L"</country>";
XmlDocument^ destDoc = gcnew XmlDocument();
destDoc->LoadXml(destXml);
XmlNode^ importedNode = destDoc->ImportNode(srcNode, true);
XmlNode^ destNode = destDoc->SelectSingleNode(
L"/country/canada");
if (srcNode == nullptr)
{
Console::WriteLine(L"'canada' node not found!");
return -1;
}
destNode->AppendChild(importedNode);
Console::WriteLine(destDoc->OuterXml);
return 0;
}
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
|
Hello,
I'm writing a web service that reads an XML from the web but this XML has some special characters that messes the reading method of the XmlReader and i can't find a way to resolve it.
here is the XML example im trying to parse to a datatable
<br />
<?xml version="1.0" ?><br />
<gsmrs_teams last_generated="20070428013954"><br />
<team team_id="2015" team_logo="true"><br />
<type>Club</type><br />
<br />
ETC.
the error looks like that:'>' is an unexpected token. The expected token is '"' or '''. Line 2, position 29.
My other Q is how can i read the output stream of the browser. Meaning how can i get the text equivalent to copy paste that i would do inside the browser text, but with asp.net methods (only text with no tags).
I want to Read text inside HTML tags.
Thanks,
Leo
|
|
|
|
|
i have the xml declaraion in 2 files but one file is able open properly in the browser on double clicking but other giving me the below error
Switch from current encoding to specified encoding not supported. Error processing resource 'file:///C:/Documents and Setti...
Can any body tell me where could be the problem
thanx in advance.
-- modified at 4:57 Monday 30th April, 2007
|
|
|
|
|
|
kalaveer wrote: Error processing resource 'file:///C:/Documents and Setti...
The browser cannot file the document with that pathname. If you are accessing the file locally, then make sure this is the correct pathname. If you are accessing the file via HTTP, make sure the pathname is a relative or absolute URL.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
hi guys,
I have failed to get a node set based on dates.
i have a simple xml
HTML Code:
<pre><code><PUBS>
<PUB>
<FIRSTINS>2006-12-08</FIRSTINS>
<LASTINS>2006-12-10</LASTINS>
</PUB>
</PUBS>
<PUBS>
<PUB>
<FIRSTINS>2004-12-08</FIRSTINS>
<LASTINS>2006-1-17</LASTINS>
</PUB>
</PUBS>
<PUBS>
<PUB>
<FIRSTINS>2007-12-08</FIRSTINS>
<LASTINS>2007-12-09</LASTINS>
</PUB>
</PUBS></code></pre>
in my xslt
HTML Code:
<pre><code><xsl:for-each select ="//PUB[FIRSTINS < LASTINS]">
..do some thing
</xsl:for-each></code></pre>
this always fails for me both less and greater than
in the above code i am using the lt; gt; but the html page is converting it to < and >
Regards
mhadamji
Mustafa
http://www.hostukdomain.com
|
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
<code>
<pubs>
<pub>
<firstins>2006-12-08</firstins>
<lastins>2006-12-10</lastins>
</pub>
</pubs>
<pubs>
<pub>
<firstins>2004-12-08</firstins>
<lastins>2006-01-17</lastins>
</pub>
</pubs>
<pubs>
<pub>
<firstins>2007-12-08</firstins>
<lastins>2007-12-09</lastins>
</pub>
</pubs>
</code>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ms="urn:schemas-microsoft-com:xslt"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="html" doctype-public="'-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'"/>
<xsl:template match="/">
<html>
<head>
<title>String Comparison</title>
</head>
<body>
<xsl:apply-templates select="code/pubs/pub[ms:string-compare(firstins, lastins) = -1]"/>
</body>
</html>
</xsl:template>
<xsl:template match="pub">
<p>
<xsl:value-of select="firstins"/> is less then <xsl:value-of select="lastins"/>
</p>
</xsl:template>
</xsl:stylesheet>
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
If <Object> is your document node (topmost node) then your XPath should be: xxPath = "/Object[@name='" & LCase(menu11.Name) & "']"
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
thanks
i found what was the problem.
|
|
|
|
|
I grabbed the following .xml and .xsd files from an online tutorial, and tried to import them into SQL Server by using XML Source. I want to be able to import ALL the data; however, the simpleType elements under the root <shiporder> are all missing from the XML source, e.g <orderpersion>. The root element, including any attributes from the root element are also missing...e.g <shiporder orderid="889923"
How can I import these missing fields? The .xml and .xsd files are below.
Any help will be greatly appreciated. Thanks.
.XML and .XSD files below.
shiporder.xml
----------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<shiporder orderid="889923"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="shiporder.xsd">
<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>
----------------
shiporder.xsd...
----------------
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="stringtype">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:simpleType name="inttype">
<xs:restriction base="xs:positiveInteger"/>
</xs:simpleType>
<xs:simpleType name="dectype">
<xs:restriction base="xs:decimal"/>
</xs:simpleType>
<xs:simpleType name="orderidtype">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{6}"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="shiptotype">
<xs:sequence>
<xs:element name="name" type="stringtype"/>
<xs:element name="address" type="stringtype"/>
<xs:element name="city" type="stringtype"/>
<xs:element name="country" type="stringtype"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="itemtype">
<xs:sequence>
<xs:element name="title" type="stringtype"/>
<xs:element name="note" type="stringtype" minOccurs="0"/>
<xs:element name="quantity" type="inttype"/>
<xs:element name="price" type="dectype"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="shipordertype">
<xs:sequence>
<xs:element name="orderperson" type="stringtype"/>
<xs:element name="shipto" type="shiptotype"/>
<xs:element name="item" maxOccurs="unbounded" type="itemtype"/>
</xs:sequence>
<xs:attribute name="orderid" type="orderidtype" use="required"/>
</xs:complexType>
<xs:element name="shiporder" type="shipordertype"/>
</xs:schema>
|
|
|
|
|
Hi!
i am storing the user defined URL in XML file by using C#. I am storing that URL inside the tag as InnerText.
if i store the URL "http://www.google.com" it works perfectly, but when i try to store the URL "http://www.google.com/search?hl=en&q=abc" it corrupts the XML file and gives error "A semi colon character was expected."
can anybody tell me what is the reason behind this error...?
Thanks,
Regards,
Affan Ahmad Toor
|
|
|
|
|
Hi
I am quiet sure that the & is the error because it is a special sign in XML. If it also doesn´t work than i might suggest the ?.
Thats the two possabilities.
Hope i helped.
|
|
|
|
|
Thanks for reply,
i checked the & sign as you suggested. You was rite, the error was because of the & sign.
Looking forward for more help from you in future...
Thanks again...
Regards,
Affan Ahmad Toor
|
|
|
|
|
|
You can overcome this prob by writing & I think. Just if you don´t have a solution.
|
|
|
|
|
You mean by writing: &
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
sure
sorry
|
|
|
|
|
replace & sign with amp;
rupesh
|
|
|
|