|
What is your problem? What language are you using?
In C# it's simple to convert a byte[] to a base64 string:
string result = System.Convert.ToBase64String(source); Then you can assign the string to the InnerText property of your XmlElement .
|
|
|
|
|
Actually i want to display an image in XML spreadsheet. Will this work in XML spreadsheet?
|
|
|
|
|
Are you trying to insert images into an Excel (XML Spreadsheet) file?
I don't know how to do it, try to look at the documentation[^].
|
|
|
|
|
Good Day
I have an XML attached in the following zipped file
and i read it like this in C#
http://www.vbforums.com/attachment.php?attachmentid=74357&d=1258368852[^]
and i read it like this in C#
DataSet ds1 = new DataSet();
StringReader rdr = new StringReader(xmlstr.ToString());
ds1.ReadXml(rdr);
and i get the Following Error
'_Chairs' is an unexpected token. The expected token is '='. Line 1, position 545.
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Vuyiswa Maseko wrote: and i get the Following Error
'_Chairs' is an unexpected token. The expected token is '='. Line 1, position 545.
Well it took me less than twenty seconds to find this token, plainly showing the syntax error. Did you try the same?
|
|
|
|
|
i found the Problem. The name of the Attribute was Desks_&_Chairs
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
I,
I am trying to use XQuery on XML data and elaborated samples are few on the web. I only find small tutorials for beginners.
Here is the query specification :
> it's a list of "vehicle";
> each "vehicle" has "flags" nodes;
> each "vehicle" is identified by a unique numeric "id" attribute;
> I want to find the lowest id verifying a list of flags ;
Here is a sample of data :
?xml version="1.0" encoding="UTF-8"?
vehicles
vehicle id="1"
flags
flag1/
flag2/
/flags
/vehicle
vehicle id="5"
flags
flag1/
flag2/
/flags
/vehicle
/vehicles
Here a sample of query on one flag :
(: smallest index index
let $d := doc( $inputDocument)//vehicle
let $e := $d/flags/flag1
return
min( $e/../../fn:number( @id))
How to process for several flags, with "and" and "or"....
Best regards
|
|
|
|
|
Hi ,
In my web application(devloped using spring framework and purely java) i have to tranform the xml data (I am getting xml from 3rd party) into the RDBMS table records of my application. Structure of both XML and table is different so its not one to one mapping. Can anybody please tell me what's the best way to do that?
Regards
Rishi Saraf
|
|
|
|
|
Hello,
I want to know what is the xpath expression when there is a space in attribute name.
e.g. /Employee/*[@Employee Name='name']
"Employee Name" is attribute name.
Thanks,
Aniruddha
|
|
|
|
|
If you have spaces in element names or in attribute names, then what you have **IS NOT XML**. XML doesn't allow spaces in element or attribute names. See the specification for names[^] (which is used for element and attribute names) in the XML spec.
So therefore, your question can only be answered logically with this statement: get rid of the spaces form your attribute names.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Aniruddha,
Just check the spec, there is no such thing as attribute names with spaces. Validation of a corresponding document should fail.
Best regrads,
Stefan
|
|
|
|
|
Given the xml snippet below, I am trying to read the Company value. I have other code which will obtain the Network Policy Zone and the Default Gateway of a given system. Using these two values, zone first, then dfgw, I need to get the Company value which correspondes so it can be set as an environment variable in a remote windows system.
Here's my mess of code, and I'm afraid it is a mess because I've been trying different things:
Sub ReadXML()
Dim attrValue, child1, child2, gChild1
getZone()
WScript.Echo "Zone is: " & zone
Set xDoc = CreateObject("Microsoft.XMLDOM") 'CreateObject("Msxml.DOMDocument") CreateObject("Microsoft.XMLDOM")
xDoc.async = False
xDoc.load ("company.xml") 'Load XML document
Set Root = xDoc.documentElement
Set NodeList = Root.getElementsByTagName(zone)
Set child1 = xDoc.documentElement.firstChild
Set child2 = child1.nextSibling
Set gChild1 = child1.firstChild
Do Until attrValue <> dfgw
attrValue = xDoc.GetAttrValue("DFGW")
WScript.Echo("DFGW Attribute Value is: " & attrValue)
xDoc.nextSibling
Loop
company = gChild1.nodeValue("Company")
WScript.Echo("Company Attribute Value is: " & attrValue)
'Set ElemList = xDoc.getElementsByTagName("Zone0")
'dfgw = ElemList.item(0).getAttribute("DFGW")
WScript.Echo("Default Gateway: " & dfgw)
'company = "BMC Software, Inc."
SetCompany(company)
End Sub
Here's the XML I'm trying to read:
<br />
<?xml version="1.0" ?> <br />
- <ZoneList><br />
- <Zone0><br />
- <DFGW><br />
"192.168.25.1" <br />
<Company>"CPC"</Company> <br />
</DFGW><br />
- <DFGW><br />
"142.101.230.1" <br />
<Company>"Test Company"</Company> <br />
</DFGW><br />
- <DFGW><br />
"" <br />
<Company>""</Company> <br />
</DFGW><br />
- <DFGW><br />
"" <br />
<Company>""</Company> <br />
</DFGW><br />
- <DFGW><br />
"" <br />
<Company>""</Company> <br />
</DFGW><br />
</Zone0><br />
- <Zone1><br />
|
|
|
|
|
XPath?
Here's some VBscript that uses XPath to select the nodes you want
Dim attrValue, child1, child2, gChild1
zone = "Zone0"
dfgw = """192.168.25.1"""
WScript.Echo "Zone is: " & zone
WScript.Echo "dfgw is: " & dfgw
Set xDoc = CreateObject("Microsoft.XMLDOM") 'CreateObject("Msxml.DOMDocument") CreateObject("Microsoft.XMLDOM")
xDoc.async = False
xDoc.load ("a.xml") 'Load XML document
xpathString = "//" & zone & "/DFGW[text() = '" & dfgw & "']/Company"
WScript.Echo xpathString
Set CompanyNodeList = xDoc.selectNodes(xpathString)
WScript.Echo CompanyNodeList.Length
You just need to be sure that the string values are correctly escaped when building the query.
Also - why the quotes around the string values?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
i have xml file
iam having c# application
i need to
1-read xml file in c# abd pass it as parameter to sql server store procedure (parameter type xml)
2- use procedure have xml parameter to insert data into table
md_refay
|
|
|
|
|
Not to put to fine a point on it, what is stopping you?
I'm not seeing a question or a problem here, just a task you have to do.
If you are having problems with your code post the problem code and errors and we can help.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
Firstly, if anyone could send me a link that explains everything that is allowed in XSD xpath expressions, I would be very grateful. I have searched for hours, and still have no idea what subset of xpath is allowed for either the selector or the field nodes. Great thanks to anyone who knows where I can find some documentation on this feature of xsd.
On to my problem... I am attempting to have an element, "parent", that contains a key attribute called "key". Every such element may have 0 or more child elements, called "Child", such that they contain a keyref attribute called "key" as well. I am wondering if there is a way to enforce through the XSD that the value of "key" for the child elements cannot be equivalent to the value of "key" for the parent node. So, for example:
<!-- XSD File -->
<xsd:element name="Example" type="ExampleType">
<xsd:key name="ParentKey">
<xsd:selector xpath="Parent"/>
<xsd:field xpath="@key" />
</xsd:key>
<xsd:keyref name="ChildKeyRef" refer="ParentKey">
<xsd:selector xpath="Parent/Child"/>
<xsd:field xpath="@key" />
</xsd:keyref>
</xsd:element>
<xsd:complexType name="ExampleType">
<xsd:sequence>
<xsd:element name="Parent" type="ParentType" maxOccurs="unbounded">
<!-- This unique portion is where I need the help. It almost works in that it prevents me from
giving a child element the parent's key, but it also has the unfortunate side effect of not
allowing me to have duplicate key references in the child elements. How can this be done? -->
<xsd:unique name="UniqueKeyRef">
<xsd:selector xpath=".|Child"/>
<xsd:field xpath="@key" />
</xsd:unique>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ParentType">
<xsd:attribute name="key" type="xsd:String" use="required"/>
<xsd:sequence>
<xsd:element name="Child" type="ChildType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ChildType">
<xsd:attribute name="key" type="xsd:String" use="required"/>
</xsd:complexType>
<-- XML File -->
<Example>
<Parent key="A">
<Child key="B"/>
<Child key="B"/> <!-- This is allowed, since it references a different element than it's parent -->
<!-- This duplicate is currently not allowed even though I want it to be. -->
<Child key="A"/> <!-- This is NOT allowed, because this element is a child of Parent "A" -->
</Parent>
<Parent key="B"/>
</Example> Hopefully this example has clearly illustrated my desire. Any number of children of Parent "A" can reference any other parent, including multiple children referencing the same parent (such as the two child elements referencing parent "B" in my example). Is there some way to rework my unique constraint, or by adding another constraint, such that these duplicates are allowed? Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
modified on Tuesday, November 3, 2009 10:19 AM
|
|
|
|
|
Not sure if this answers your question ( I didn't read it all ), but I've always used this[^] when I need to do XSLT/XPath stuff.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
The Essential XML Quick Reference[^] is an excellent (and free) XML (+ XSD + XPath + XSLT) reference.
On page 349, it defines the available XPath selectors (I'd copy them here, but it disallows copying - grrrr).
However, I don't think you can do what you want with the 'unique' relation. The correctness 'uniqueness' set would be '..|.' using the Child element as the context node. But you can't do that with XML Schemas.
Using the Parent as context node, there's no way to define the uniqueness set, I don't think, as there are n sets, where n==number of Child nodes.
However - using Schematron[^], you can validate this rule using this Schema:
<schema xmlns="http://www.ascc.net/xml/schematron" >
<pattern name="Check CHild/Parent keys">
<rule context="Child">
<assert test="@key!=../@key">Child key should differ from Parent key.</assert>
<report test="@name">Child key should differ from Parent key.</report>
</rule>
</pattern>
</schema>
This should be used in addition to a schema describing the basic structure of the XML. Using xmllint (which comes with libxml2), I can confirm that this Schematron schema meets your requirements.
XML files can be validated against Schematron schemas using an XSLT processor, so even if your XML parser doesn't have Schematron support, you can still use Schematron.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Yeah, that is what I was afraid of... I know I could do it using XSD 1.1 or, as you suggested, Schematron, but validating against either of those options isn't well supported (at least as far as I can tell) in Java or C. I actually tried what you suggested with the parent element, saw it wasn't supported, and figured that there must just be some other well-hidden way to go about it. I don't want to have a second definition file, so embedded Schematron may be the answer right now (if I can figure out how to validate against it), or I could just wait until next April when the XSD 1.1 specification is finalized. Anyway, thank you very much for the help!
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Schematron is supported by libxml2, so (therefore) is accessible to C or C++ or anything else that exposes that part of libxml2 through a binding.
The Schematron website describes the steps needed to perform Schaematron validation:
xslt -stylesheet iso_dsdl_include.xsl theSchema.sch > theSchema1.sch
xslt -stylesheet iso_abstract_expand.xsl theSchema1.sch > theSchema2.sch
xslt -stylesheet iso_svrl_for_xsltn.xsl theSchema2.sch > theSchema.xsl
xslt -stylesheet theSchema.xsl myDocument.xml > myResult.xml
Basically, generate an XSLT file from your Schematron schema (the first three steps). Then process the input XML file using your XSLT processor and the generated XSLT file to output something that tells you if the XML is valid per the Schematron schema.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I am using c# serialisation to write some xml. For some reason the output is not necessarily written in the order it appears in the code.
How can I order the elements?
For example:
[Serializable]
public class Request
{
[XmlElement("Type")]
public string Type
{
get;
set;
}
[XmlElement("Id")]
public int Id
{
get;
set;
}
}
Would write
<Request>
<Id>1</Id>
<Type>Get</Type>
</Request>
(Note this example is very simplified and doesn't actually write it wrongly).
|
|
|
|
|
Fixed it.
It turns out, fields are serialised before properties and my code was actually like this:
[Serializable]
public class Request
{
[XmlElement("Type")]
public string Type
{
get;
set;
}
[XmlElement("Id")]
public int Id;
}
|
|
|
|
|
I have just been successfull at generating an element centric xml query using linq to my sqlserver database. Can someone show me an example how to do it to generate an attribute centric result?
I also am able to save the results to a file on my c drive but need to save it to an xml file in my project.
Thank you in advance.
|
|
|
|
|
I am generating a Excel Sheet(XML SpraedSheet) through XSLT transform.How to password protect the XML SpreadSheet in XSLT.
Is there is any tag to password Protect?
Is there is any other solutions to password protect the XML Spreadsheet?
Best Regards
|
|
|
|
|
It's as if you understand XSLT, and yet somehow have no idea what XML is. How is that possible ?
XML is a string. You can write external code to encode the entire string ( meaning it won't be XML anymore ), or to encode the contents of the nodes. You'd then need corresponding code to decode the information. You can invent a 'password protect tag', but it's plainly not going to alter the fact that all you have is a plain text file.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|