|
There is no date conversion code in your question. All you're doing is copying the input value to the output, and appending some static text.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I am using a list of a class. Serialization works fine, but Deserialization leads to creating new lists, which are appended to main list. I.e. if Deflists in AllKeyList contains 5 KeyDefinition Classes, after Deserialization there are 10.
How can I force overriding?
Thx adv for your help.
What I'm doing:
FileStream fs = new FileStream(sFile, FileMode.Open);
var x = new System.Xml.Serialization.XmlSerializer(Setup.GetType());
var settings = new XmlReaderSettings { CheckCharacters = false, };
try
{
Setup = (DataSettings)x.Deserialize(fs);
Console.WriteLine("XML Read {0} erfolgreich", sFile);
Data structure:
public class KeyDefinition
{
public string Name { get; set; }
public string KeyType { get; set; }
public List<FieldToken> KeyDef { get; set; }
....
}
public class AllKeyList
{
public List<KeyDefinition> DefLists { get; set; }
...
}
modified 17-Jul-18 5:00am.
|
|
|
|
|
Hello all,
I just started learning HTML and I would like to save the value entered to a selected data list option.
<pre>
<!DOCTYPE html>
<html>
<head>
<title>Program using HTML </title>
<body bgcolor="LightGray" text="Black">
<form name="NUM">
<input list="document">
<datalist id="document">
<option value="wireset_623101">
<option value="wireset_623102">
<option value="wireset_623103">
<option value="wireset_623104">
<option value="wireset_623105">
<option value="wireset_623106">
<option value="wireset_623107">
<option value="wireset_623108">
<option value="wireset_623109">
<option value="wireset_623110">
<input value="button">
</datalist>
= <input name="number">
<br>
<input type="button" value=" 1 " onClick="document.NUM.number.value+='1'">
<input type="button" value=" 2 " onClick="document.NUM.number.value+='2'">
<input type="button" value=" 3 " onClick="document.NUM.number.value+='3'">
<button type="button" onclick="document.write(document.NUM.number.value +' wireset_623101')">NEXT></button>
<br>
<input type="button" value=" 4 " onClick="document.NUM.number.value+='4'">
<input type="button" value=" 5 " onClick="document.NUM.number.value+='5'">
<input type="button" value=" 6 " onClick="document.NUM.number.value+='6'">
<button type="button" onclick="document.write(document.NUM.number.value +'wireset_623110' )">ENTER</button>
<br>
<input type="button" value=" 7 " onClick="document.NUM.number.value+='7'">
<input type="button" value=" 8 " onClick="document.NUM.number.value+='8'">
<input type="button" value=" 9 " onClick="document.NUM.number.value+='9'">
<br>
<input type="button" value=" 0 " onClick="document.NUM.number.value+='0'">
</form>
<script>
</script>
</head>
</body>
</html>
|
|
|
|
|
Hello,
I need to validate an XML file using an XSD scheme imposed by a provider.
For that I use the library libxml2 version 2.9.4 and msxml6 under Windows and I get different results.
With libxml2 the XML file is not valid on Windows or Linux.
With MSXML6 the XML file is considered valid.
Below are some simplified examples. To easily validate the XML file with the XSD, I use Microsoft Visual Studio (msxml) and compare with Notepad ++ (XMLTools plugin that apparently uses libxml2).
XML file :
<?xml version="1.0" encoding="utf-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:root="http://www.xmlValidation.com/root" xsi:schemaLocation="./schema_strict.xsd">
<object identifier="1ABC001DE"/>
</root>
XSD file :
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:complexType name="codeType">
<xs:attribute name="identifier" use="required">
<xs:simpleType>
<xs:restriction base="xs:NMTOKEN">
<xs:maxLength value="10"/>
<xs:pattern value="\d\p{Lu}\p{Lu}\p{Lu}\d\d\d\p{Lu}\p{Lu}(\p{Lu}|\d|)"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="object" type="codeType" minOccurs="0">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
By adding a "?" at the end of the control pattern, the validation is ok with libxml and msxml: \d\p{Lu}\p{Lu}\p{Lu}\d\d\d\p{Lu}\p{Lu}(\p{Lu}|\d|)?
Not at all comfortable with regular expressions and XSDs I need help on this topic.
Do you think that libxml is stricter than msxml? is the interpretation of the regular expression ambiguous?
Thank you very much !
|
|
|
|
|
The question mark makes the preceeding portion optional. That is it might be absent or present one time but not multiple times.
But you have an empty OR condition:
(\p{Lu}|\d|) I would change it to
(\p{Lu}|\d) I guess that the regex implementation used by libxml fails here while those of MSXML ignores it.
|
|
|
|
|
I am using XmlElements and AppendChild to create an XML tree. Now, the first level from the root writes on a new line but all other XmlElements write on the same line. How do I get each new XmlElement to write on a new line with proper indentation?
My code:
XmlAttribute ApplicantAttribute = doc.CreateAttribute("UserId");
ApplicantAttribute.Value = NumberGenerator(100000, 999999, 6);
Applicant.Attributes.Append(ApplicantAttribute);
XmlNode ssnNameNode = doc.CreateElement("SSN");
ssnNameNode.AppendChild(doc.CreateTextNode(NumberGenerator(0, 999999999, 9)));
Applicant.AppendChild(ssnNameNode);
XmlNode aNameNode = doc.CreateElement("Name");
aNameNode.AppendChild(doc.CreateTextNode("Place Holdor Name"));
Applicant.AppendChild(aNameNode);
XmlNode demDataNode = doc.CreateElement("DemographicData");
demDataNode.AppendChild(doc.CreateTextNode("DemographicData"));
aNameNode.AppendChild(demDataNode);
XmlNode FullName = doc.CreateElement("FullName");
FullName.AppendChild(doc.CreateTextNode("FullName"));
demDataNode.AppendChild(FullName);
XmlNode LegalName = doc.CreateElement("LegalName");
LegalName.AppendChild(doc.CreateTextNode("LegalName"));
FullName.AppendChild(LegalName);
XmlNode Last = doc.CreateElement("Last");
Last.AppendChild(doc.CreateTextNode("Last"));
LegalName.AppendChild(Last);
XmlNode First = doc.CreateElement("First");
First.AppendChild(doc.CreateTextNode("First"));
LegalName.AppendChild(First);
Applicant.AppendChild(demDataNode);
RequestNode.AppendChild(Applicant);
The problem is that the output writes the following Xml file:
<Applicant UserId="830046">
<SSN>811163249</SSN>
<Name>Place Holdor Name</Name> <DemographicData>DemographicData<FullName>FullName<LegalName>LegalName<Last>Last</Last><First>First</First></LegalName></FullName></DemographicData>
</Applicant>
|
|
|
|
|
Doesn't matter if xml nodes are in the same line untill the xml is well formatted.
|
|
|
|
|
Bootzilla33 wrote:
I asked this question in another thread but no one answered it so I'm creating a new thread to see if someone can help. I need help with pass the value in the API to XElement in C#
Here the a piece of the API schema:
<xsd:element
name="EventStatus" type="xsd:string">
<xsd:annotation>
<xsd:documentation>Event Status</xsd:documentation>
</xsd:annotation>
</xsd:element>
Is this how that would be done?
new XElement("EventStatus", "Event Status"),
), |
|
|
|
|
|
Your question is not very clear, but I assume you want to create an XElement that when written to a file will look like this
<xsd:element name="EventStatus" type="xsd:string">
<xsd:annotation>
<xsd:documentation>Event Status</xsd:documentation>
</xsd:annotation>
</xsd:element>
This is one way to do it.
XNamespace ns = "should probably be the XSD namespace";
XElement documentation = new XElement(ns + "documentation");
documentation.SetValue("Event Status");
XElement annotation = new XElement(ns + "annotation");
annotation.Add(documentation);
XElement eventStatus = new XElement(ns + "element");
eventStatus.SetAttributeValue(XName.Get("name"), "EventStatus");
eventStatus.SetAttributeValue(XName.Get("type"), "xsd:string");
eventStatus.Add(annotation);
XElement root = new XElement("root", new XAttribute(XNamespace.Xmlns + "xsd", ns));
root.Add(eventStatus);
string s = root.ToString();
|
|
|
|
|
Hi,
I make my question after some research in web without any clear response to my problem.
I have the following XML and I need to apply an XSL transformation to get only nodes which haven't child.
Input :
<Root_Element Att_Name="XXX">
<right Id="100">
<right Id="110" />
<right Id="111">
<right Id="112" />
<right Id="113">
<right Id="114" />
<right Id="115" />
</right>
<right Id="116" />
</right>
<right Id="117">
<right Id="118" />
<right Id="119">
<right Id="120" />
<right Id="121" />
</right>
</right>
</right>
</Root_Element>
Expected output :
<Root_Element Att_Name="XXX">
<right Id="110" />
<right Id="112" />
<right Id="114" />
<right Id="115" />
<right Id="116" />
<right Id="118" />
<right Id="120" />
<right Id="121" />
</Root_Element>
|
|
|
|
|
Something like this should work:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Root_Element">
<xsl:element name="{name()}">
<xsl:apply-templates select="*|@*"/>
</xsl:element>
</xsl:template>
<xsl:template match="*">
<xsl:choose>
<xsl:when test="count(*) = 0">
<xsl:element name="{name()}">
<xsl:apply-templates select="@*"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="*" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
I have already gone through MSDN and multiple good known resources.
but I don't have time to elaborate and go deep in it.
I just want to give me best practices library for deeply working on xslt, XML resolver, and class library where I can implement my actual business logics using c#.Net and TPL.
|
|
|
|
|
Member 11785909 wrote: I don't have time You may find that no one here does either.
|
|
|
|
|
Apparently you were correct.
|
|
|
|
|
No surprise there.
|
|
|
|
|
I am trying to transform an XML file through code using XSL, but for some reason, the file output is displaying the entire XML as a string at the top of the document and then, just under the XML string, the document is parsed correctly by the XSL stylesheet. I would like to learn why this is happening. Here is the VB transform code:
Dim ds As New DataSet
ds.ReadXml(Server.MapPath("FormResults/" & FormID.ToString() & ".xml"))
Dim DocXSL As New XslCompiledTransform
Dim sw As New StringWriter()
ds.WriteXml(sw)
ds.Dispose()
Dim DocXML As New XmlDocument
DocXML.LoadXml(sw.ToString())
'The GetXSLContent function returns the XLS template to be used
DocXSL.Load(GetXSLContent(DFLID))
DocXSL.Transform(DocXML, Nothing, sw)
Dim result As String = sw.ToString()
sw.Close()
sw = Nothing
Me.My_Literal.Text = result.ToString()
Private Function GetXSLContent(ByVal DFLID As Integer) As String
Dim str As String = String.Empty
str = Server.MapPath("FormLetters/" & DFLID.ToString() & "_DataTemplate.xslt")
Return str
End Function
Here is the XML
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Results>
<Fields ID="48">
<Department>I.T.</Department>
<Extension>2267</Extension>
<Location>Primary Office Bldg</Location>
<Name_of_User>David</Name_of_User>
<Date>9/12/2014</Date>
<Time>04:49</Time>
<Details1>This is a test. asdf sasdf sa</Details1>
<Details2>This is only a test.</Details2>
<Details3>This is a test.</Details3>
<Details4>This is only a test.</Details4>
<Details5>This is a test.</Details5>
<Details6>This is only a test.</Details6>
<Details7>This is a test.</Details7>
<Details8>This is only a test.</Details8>
</Fields>
</Results>
Here is the XSLT
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" encoding="utf-8" omit-xml-declaration="yes"/>
<xsl:template match="/">
<div class="rndc" style="left:50%;right:50%;margin:auto;width:90%;border: 1px solid #e0e0e0;padding: 0px 5px 0px 5px">
<xsl:for-each select="Results/Fields">
<div style="text-align:left;vertical-align:top;padding: 0px 5px 0px 5px;width:96%;white-space:pre-wrap;display:inline-block">
<table style='border-collapse: collapse; left: 50%; right: 50%; margin: auto; width: 80%'>
<tr>
<td class="txtlrg" style="vertical-align:top;text-align:left" colspan="2"> <xsl:value-of select="Department"/> </td>
</tr>
<tr>
<td style="vertical-align:top;text-align:right">User Name:</td>
<td><xsl:value-of select="Name_of_User"/></td>
</tr>
<tr>
<td style="vertical-align:top;text-align:right">Extension:</td>
<td><xsl:value-of select="Extension"/></td>
</tr>
<tr>
<td style="vertical-align:top;text-align:right">Location:</td>
<td><xsl:value-of select="Location"/></td>
</tr>
<tr>
<td style="vertical-align:top;text-align:right">Date & Time:</td>
<td style="white-space:pre"><xsl:value-of select="Date"/> <xsl:value-of select="Time"/></td>
</tr>
<tr>
<td style="vertical-align:top;text-align:right">Details:</td>
<td style="white-space:pre"><xsl:value-of select="Details1"/><br />
<xsl:value-of select="Details2"/><br />
<xsl:value-of select="Details3"/><br />
<xsl:value-of select="Details4"/><br />
<xsl:value-of select="Details5"/></td>
</tr>
</table> </div>
<div style="page-break-before: always;"></div>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>
Here's the output:
I.T. 2267 Gov. Center Vickie 9/12/2014 04:49 This is a test. asdf sasdf sa This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test.
I.T.
User Name: David
Extension: 2267
Location: Primary Office Bldg
Date & Time: 9/12/2014 04:49
Details: This is a test. asdf sasdf sa
This is only a test.
This is a test.
This is only a test.
This is a test.
Thanks in advance!
|
|
|
|
|
TML wrote:
Dim sw As New StringWriter()
ds.WriteXml(sw)
...
DocXSL.Transform(DocXML, Nothing, sw)
Dim result As String = sw.ToString()
You've declared a single StringWriter instance. You've written the XML to it. Then you've written the results of the transformation to it.
It's hardly surprising that it then contains both the XML and the results of the transformation.
After loading the XML, you either need to create a new StringWriter instance, or you need to clear the existing one.
...
DocXML.LoadXml(sw.ToString())
sw.GetStringBuilder().Clear()
...
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
If it was a snake, it would have bit me. Thanks Richard!
|
|
|
|
|
i want to save an xml file that will look like:
"http://www.codeproject.com/script/Membership/Uploads/1234567/update.xml"
i really need help how to do this.
When i do this in google drive the link to the file do not contain .xml extension.
|
|
|
|
|
Link does not go anywhere. You need to explain your problem in proper detail.
|
|
|
|
|
iam sorry i did not explain very well.
it is not the actual link...
i mean i want to store my update.xml file somewhere on the remote location and access its link as something link www.website.com/update.xml and not as www.googledrive.com/id?=xskdhfIsksdhf
it is because i want to compare the two files update.xml in the local drives, and the www.website.com/update.xml from from remote location.
Thank you for your response.
|
|
|
|
|
Sorry I still do not understand what your problem is, or what this has to do with XML/XSL.
|
|
|
|
|
Do you have access to a domain / web site called "www.website.com"?
If you did, you would typically put "update.xml" in you website's "root directory"; or you would use some form of "redirection" to resolve the supplied address (e.g. MVC routing).
Is that clear?
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Just make a google spreadsheet, that's all.
|
|
|
|