how to add uri of lexicon file in xml - c#

I am writing code for custom grammar for that I created a lexicon file which I am using in XML grammar file. I want to add the lexicon with my software to the end user as an embedded resources so how can i reference it's uri in XML?
my XML codes are
<?xml version="1.0" encoding="utf-8"?>
<grammar
version="1.0" mode="voice" root="Voice_Automator"
xml:lang="en-IN" tag-format="semantics/1.0"
sapi:alphabet="x-microsoft-ups"
xml:base="http://www.contoso.com/"
xmlns="http://www.w3.org/2001/06/grammar"
xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions">
**<lexicon uri="C:\Users\Agrawal\Documents\Visual Studio 2010\Projects\123.pls" />**
i want to use 123.pls file as an embedded resource so at the end user the program should load it properly

Use one of the XML link mechanisms:
XLink
<lexicon xmlns:link="http://www.w3.org/1999/xlink" xlink:href="C:\Users\Agrawal\Documents\Visual Studio 2010\Projects\123.pls"/>
External Entity
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE foo [<!ENTITY bar SYSTEM "C:\Users\Agrawal\Documents\Visual Studio 2010\Projects\123.pls"> ]>
<grammar version="1.0" mode="voice" root="Voice_Automator" xml:lang="en-IN" tag-format="semantics/1.0" sapi:alphabet="x-microsoft-ups" xml:base="http://www.contoso.com/" xmlns="http://www.w3.org/2001/06/grammar" xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions">
<? &bar; ?>
</grammar>
References
XML Linking Language
XML Linking and Style
XML: How to read one file into another
XML: How to load the contents of one xml file into another
How do I check for the existence of an external file with XSL?
how to use xpointer to link to specific node from another document
Generate HTML / Help files from VS 2010 C# XML documentation

Related

Read a section in FHIR Document Reference Data

Is there any way to read a CCD Data section inside the CCDA XML using FhirSerialization in R4.
I have a DocumentReference FHIR Object and in that I have DATA section in a byte format. I have converted it to a string using the below line.
string decodedSamlRequest = System.Text.Encoding.UTF8.GetString(dfv);
and now in this decodedSamlRequest I have the CCD XML content.
<?xml version="1.0" encoding="UTF-8"?>
<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:voc="xyz" xmlns:sdtc="xyz" xmlns:xsi="xyz">
<realmCode code="US"/>
<assignedCustodian>
<representedCustodianOrganization>
<id root="123" extension="92"/>
<name>some xyz</name>
<telecom use="WP" value="tel:1234"/>
<addr use="WP">
<streetAddressLine>address</streetAddressLine>
<city>city</city>
<state>state</state>
<postalCode>12345</postalCode>
<country>US</country>
</addr>
</representedCustodianOrganization>
</assignedCustodian>
</custodian>
</ClinicalDocument>
In this I need to read the CITY element under Custodian Tag.
From FHIR's perspective, all content within an attachment is opaque. You can certainly write code to parse, access and manipulate that content - and could even create custom SearchParameters that could filter based on it. But you can't navigate into it using FHIRPath or using the navigation machinery found in any of the reference implementations.

Convert FBX to to xml using C#

I just want to make a simple windows form application that allows the user to select a .fbx file and then it will save as an XML file. I know how to use the select file dialog and XML serialization. Just stumped when it comes the FBX handling. I just need the Verts, triangles and first UVs. No animations or materials.
Anyway Here's the XML format I need:
<?xml version="1.0" encoding="utf-8"?>
<MeshInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<verts>
<Info_Vector3>
<x>8.785349</x>
<y>7.7458005</y>
<z>1.65082479</z>
</Info_Vector3>
<Info_Vector3>
<x>8.785349</x>
<y>0.427168041</y>
<z>1.65079832</z>
</Info_Vector3>
// etc...
</verts>
<triangles>
<int>0</int>
<int>1</int>
<int>2</int>
<int>0</int>
// etc...
</triangles>
<uvs>
<Info_Vector2>
<x>8.785349</x>
<y>0.427168041</y>
</Info_Vector2>
// etc...
<uvs />
</MeshInformation>

Copying an existing XML file to a new XML file

I have an existing XML file that has the following start element:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mynms SYSTEM 'mynms20.dtd'>
<mynms version="2.0" xmlns="mynms20.xsd"> <!-- This is the troublesome line-->
<cmData type="actual">
<header>
<log dateTime="2011-10-17T06:07:07" action="created" appInfo="ActualExporter">InternalValues are used</log>
</header>
.....
</cmData>
I'm reading this file using c#'s XMLReader and then altering certain elements of the file as above and outputing the new xml in another file using c#'s XMLWriter.
So when the XMLReader reads in an element, I have the following:
writer.WriteStartElement(xmlReader.Prefix, xmlReader.Name, null);
writer.WriteAttributes(xmlReader, true); <!-- This causes the assertion. Take this out then everything is OK -->
But I get an exception stating The prefix ' ' cannot be redefined from ' ' to 'mynms20.xsd' within the same start element tag. <--- What does this mean and how can I just copy the namespace and attributes over to another file?
Many thanks.

Reading a template and creating a new XML file using the read template

I'm attempting to read a XML template, code below, and put this content to a new XML file.
<?xml version="1.0" encoding="utf-8"?>
<Format>
<Name title=""></Name>
<FormatA>
<Scheme name="A" set="number" get="integer">
<Sample set="number" get="integer">33</Sample>
</Scheme>
</FormatA>
<FormatX>
<Scheme name="A" set="number" get="integer">
<Sample set="number" get="integer">44</Sample>
</Scheme>
</FormatX>
</Format>
And will input values and write the title and a value for name. e.g When I enter "Counter" for the title and "Cnt" for the value. It will write
<Name title="Counter">Cnt</Name>
Basically, I'll just copy the contents of the template, put it in the new XML file with the inputted title and value.
Thank you for reading and who will answer my inquiry.
Did you tried string.Format?
Create the Template XML file with
Place Holders, like this {1}
Call
String.Format(XmlContent,"Counter","Cnt")
Hope it helps.

Merging XML files using external entities in Visual Studio 2008

I have some xml data contained in three files (Database.xml, Participants.xml, and ConditionTokens.xml). I am trying to use external entities to place the participants and condition tokens into the database file, but when I run this code...
string xmlPath = Environment.CurrentDirectory + #"\Data\Database.xml";
XElement database = XElement.Load(xmlPath);
...there are no participants or condition tokens in my xml (the HasElements property for "database" is false). There should be two child elements. I get no errors/warnings within Visual Studio (2008), and the live schema validation seems to be happy, but something is not quite right when I run my code.
Could anyone tell me what I'm doing wrong?
I have pasted the three xml files below.
Thanks very much!
-Dan
Database.xml
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE database [
<!ENTITY conditionTokens SYSTEM "ConditionTokens.xml">
<!ENTITY participants SYSTEM "Participants.xml">]>
<database
xmlns="experimentManager"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="experimentManager Database.xsd">
&conditionTokens;
&participants;
</database>
ConditionTokens.xml
<?xml version="1.0" encoding="utf-8" ?>
<conditionTokens>
<conditionToken>
<id>1</id>
<token>LargeToSmall</token>
</conditionToken>
<conditionToken>
<id>2</id>
<token>SmallToLarge</token>
</conditionToken>
</conditionTokens>
Participants.xml
<?xml version="1.0" encoding="utf-8" ?>
<participants>
<participant>
<id>1</id>
<conditionTokenId>1</conditionTokenId>
</participant>
<participant>
<id>2</id>
<conditionTokenId>2</conditionTokenId>
</participant>
</participants>
I would have used the XmlDocument class to load the 3 documents
XmlDocument xmlDatabase = new XmlDocument();
xmlDatabase.Load(databasePath);
XmlDocument xmlTokens = new XmlDocument();
xmlTokens.Load(tokensPath);
XmlDocument xmlParticipants = new XmlDocument();
xmlParticipants.Load(participantsPath);
Then using the ImportNode and AppendNode attach then to each other...
xmlDatabase.FirstChild.AppendNode(xmlDatabase.ImportNode(xmlTokens.FirstChild), true);
xmlDatabase.FirstChild.AppendNode(xmlDatabase.ImportNode(xmlParticipants.FirstChild), true);
That should pretty much do it (or instead of using FirstChild use an xpath selector?)
I ended up using <xs:redefine> instead.

Categories

Resources