无法使用XDocument获取元素(Not able to get the element with XDocument)
下面是我用来获取“人物”的“名称”(属性)值的代码
parameter tag =“person”和parameter attribute =“name”
public static string GetInformationFromXML(string tag, string attribute, string filePath) { XDocument doc = XDocument.Load(filePath); string info = doc.Element(tag).Attribute(attribute).Value; return info; }
doc.Element(tag)没有得到元素,即使我扩展doc时,它确实有一个元素类型为'Element'而名称'person'正在读取的文件是XmlDocument供您参考。
下面是我想要阅读的文件的xml
<?xml version="1.0"?> <import> <company name1="ABC" name2="" action="create" profile="\Profiles\ABC\" id="C1"> <address street="industrial" city="london" country="england" id="A1"> <telecom type="phone" value="4839282992" desc="" default="true" /> <telecom type="fax" value="3232" desc="" /> </address> </company> <person title="Mr." name="Tariq" surname="sheikh" lang="EN" action="create" profile="Profiles\Tariq" login="tariq" password="123456" default_address="A1"> <link reference="C1" type="Employee" description="Software developer" /> <address street="baker street" zip="12443" city="london" country="england" /> <account bank="Barclays" account="4378734834" /> <telecom type="email" value="tariq.sheikh@abc.co.in" desc="" /> <registration type="temporaryID" value="4623648c-739e-49c8-93fa-41dc7fed53ea" /> </person> </import>
我是XDocument的新手!
Below is the code i am using to get the value of the 'name'(attribute) of the 'person'
parameter tag="person" and parameter attribute="name"
public static string GetInformationFromXML(string tag, string attribute, string filePath) { XDocument doc = XDocument.Load(filePath); string info = doc.Element(tag).Attribute(attribute).Value; return info; }
doc.Element(tag) is not getting the element even though when i expand doc, it does have an element with type 'Element' and Name 'person' the file being read is XmlDocument for your information.
below is the xml of the file i am trying to read
<?xml version="1.0"?> <import> <company name1="ABC" name2="" action="create" profile="\Profiles\ABC\" id="C1"> <address street="industrial" city="london" country="england" id="A1"> <telecom type="phone" value="4839282992" desc="" default="true" /> <telecom type="fax" value="3232" desc="" /> </address> </company> <person title="Mr." name="Tariq" surname="sheikh" lang="EN" action="create" profile="Profiles\Tariq" login="tariq" password="123456" default_address="A1"> <link reference="C1" type="Employee" description="Software developer" /> <address street="baker street" zip="12443" city="london" country="england" /> <account bank="Barclays" account="4378734834" /> <telecom type="email" value="tariq.sheikh@abc.co.in" desc="" /> <registration type="temporaryID" value="4623648c-739e-49c8-93fa-41dc7fed53ea" /> </person> </import>
I am new to XDocument !
原文:https://stackoverflow.com/questions/15403678
最满意答案
您可以执行软重置回主分支的头部,这将维护您当前的工作目录,但将分支和索引重置为主。
git reset --soft master
一切都会恢复到你提交之前的状态。 然后您可以添加单个文件。
git add <file>
添加个别文件的一部分。
git add --patch <file>
或者全身心投入并使用完整的交互式添加。
git add --interactive
有关深入指南,请参阅Pro Git Book中的交互式分段的完整章节。
You can do a soft reset back to the head of the master branch, which will maintain your current working directory but reset the branch and index back to master.
git reset --soft master
Everything will be back the way it was before your commit. You can then add individual files.
git add <file>
Add parts of individual files.
git add --patch <file>
Or go whole hog and use full interactive add.
git add --interactive
See the full chapter on interactive staging in the Pro Git Book for an in depth guide.
相关问答
更多-
https://www.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html Cherry-pick会创建新的提交,因此如果省略分支中不存在但存在于分支中的文件,您将要合并,最终不会发生任何事情。 mkdir test && cd test && git init && touch foo.txt git add foo.txt && git commit -m "Init repo" git branch test && git checkou ...
-
我会选择引入所需部分的提交,然后git reset HEAD^以删除最新的提交并将更改保留在工作副本中,然后git add -p您想要的部分并从中进行新的提交。 I would cherry-pick the commit that introduces the parts you want, then git reset HEAD^ to remove the most recent commit and leave the changes in the working copy, then git ad ...
-
如何有效地从git分支中挑选文件删除,创建和移动?(How to pick file deletions, creations and moves from a git branch efficiently?)[2023-03-08]
您可以执行软重置回主分支的头部,这将维护您当前的工作目录,但将分支和索引重置为主。 git reset --soft master 一切都会恢复到你提交之前的状态。 然后您可以添加单个文件。 git add添加个别文件的一部分。 git add --patch 或者全身心投入并使用完整的交互式添加。 git add --interactive 有关深入指南,请参阅Pro Git Book中的交互式分段的完整章节。 You can do a soft reset back to ... -
如果它们是作为两个单独的提交完成的话,那么不应该这样做,因为这些文件将在一个修订版本中被删除,并且在新版本中创建一个新文件。 如果你想保留重命名,你应该做一个git commit --amend来追加你的添加到前一个提交的删除。 Not if they're done as two separate commits, because the files will have been deleted in one revision and a new file created in the new revis ...
-
使用分支命名空间有效备份许多版本的git仓库(Efficiently backup many versions of a git repo with branch namespacing)[2022-09-13]
为什么开发人员需要推送omni-backup回购? 出于备份目的,我宁愿将不同开发人员的存储库注册为远程存储库,并在所有远程存储库上每晚(从omni-backup服务器)执行git fetch 。 这样,没有分支名称可能串通。 一个更自动化的过程(开发人员不必明确地推送他/她不直接使用的回购中的任何内容,但只考虑备份) 然后我会从omni-backup生成一个漂亮的小git archive并将其存储起来。 Why would you need for developer to push to omni-ba ... -
您可以将这些提交转换为修补程序,手动编辑修补程序(用新路径替换旧路径)然后应用。 $ git init Initialized empty Git repository in /tmp/gitt/.git/ $ mkdir olddir $ cp /home/vi/code/_/ucontext.cpp olddir/ucontext.cpp $ git add . $ git commit -m "initial commit" [master (root-commit) c0bf371] initial ...
-
Git Cherry-Pick(Git Cherry-Pick)[2023-09-08]
很高兴帮助:)如果master中的那个将是永久的方式,我会修复主题分支中的文件结构以匹配master,提交到分支,* 然后将更改合并到master,而不是cherry-pick。 如在 git checkout branch mv other/subdir/file subdir/file git status // git add and git rm to get the commit proper git commit -m "fixing file struct" git checkout mast ... -
这是常见行为,已在文档中进行了描述。 首先,为什么你的复制不会造成合并冲突 ? 在合并期间,将更新工作树文件以反映合并的结果。 在对共同祖先版本所做的更改中, 非重叠版本(即,您更改文件的某个区域而另一侧保持该区域完整,反之亦然)将逐字汇入最终结果中。 同一段落中的下一句话描述了为什么在没有--rebase情况下将origin --rebase您的主人--rebase来创建合并冲突: 然而,当双方对同一区域进行更改时,Git不能随意选择一方而不是另一方,并要求您通过将双方所做的事留在该区域来解决它。 合并冲 ...
-
我假设你只需要将该文件重置为master上的版本,而不是删除任何更改历史记录,对吗? 前者很容易,后者需要修改历史记录,不应轻易做到(特别是如果你把分支推到当地回购之外)。 要将文件foo/bar/baz.txt的内容重置为foo/bar/baz.txt上的状态,只需检查分支并运行 git checkout master -- foo/bar/baz.txt 这将从master获取文件,将其写入工作副本,并在索引中暂存。 你现在可以只是git commit ,你的文件现在将匹配master 。 I ass ...
-
概要 不能仅合并提交的一部分。 但是,您可以在C5之前reset (软或混合)提交,在两个单独的提交中提交更改和删除,并在其上应用您的其他提交。 但是,这将更改您的分支历史记录,因此如果您将分支推送到远程和/或其他任何人在您的提交之上工作, 则不应该这样做。 细节 第一个可取的步骤,就像你想弄乱你的分支机构的历史一样,就是创建一个备用分支,以防一切都向南。 git branch backup_branch做到这一点。 如果你搞砸了所有东西,你可以git checkout backup_branch并在你的旧 ...